LoginSignup
6
5

More than 5 years have passed since last update.

goでのtypeの一括宣言

Last updated at Posted at 2016-08-25

typeの一括宣言

今の今まで気づきませんでしたが
constやvarのようにtypeも一括宣言できるようです。

package main
//const宣言
const GO = "go"
const GOLANG = "golang"

//constは以下のようにも書ける
const (
  GO = "go"
  GOLANG = "golang"
)

//type宣言
type Go struct{
  gopher string
}
type Golang int

//実はtypeも同じことが可能
type (
  Go struct{
    gopher string
  }
  Golang int
)

constの一括宣言は周知されているものと思いますが
typeの一括宣言は知らない方も多いんじゃないでしょうか。
https://golang.org/ref/spec
もちろん普通に仕様には載っているんですが
仕様をまともに読まないカスのような人は、中々気づかないか忘れているはずです。
自分だけではないことを祈ります。

基本的にメソッドがtype宣言の下に書かれることが多く、
使い時が少なそうですが覚えておいて損はないと思います。

6
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
5