ãã®èšäºã§ã¯ã次ã®ããšãåŠç¿ããŸãã
- Javaã®ã€ã³ã¿ãŒãã§ãŒã¹ãšã®éãã¯äœã§ãã
- ãããã®éãã®éèŠãã€éèªæãªçµæ
- ã€ã³ã¿ãŒãã§ãŒã¹ããã³ãããã®äžã«ã©ã®ããã«é 眮ãããŠããã
- 空ã®ã€ã³ã¿ãŒãã§ã€ã¹ãèŠããŠãã ããïŒã€ã³ã¿ãŒãã§ã€ã¹{}ïŒ
- ãžã§ããªãã¯ã«é¢ããç¥èãªãããã¯ã«è§Šãã
- 誰ãããªãã€ã³ã¿ãŒãã§ãŒã¹ãäœæããå¿ èŠãããããèŠãŠã¿ãŸããã
- ã€ã³ã¿ãŒãã§ãŒã¹ãä¹±çšããã«ç掻ãå§ããããšãåŠã¶
ïŒ Svitlana Agudovaã«ããã¢ãŒãã¯ãŒã¯ ïŒ
çŽäº€æ§
ããã§ã¯ãæåã®éèŠãªãã€ã³ãããå§ããŸããããããã¯éåžžã«ç解ããããã§ã- ã€ã³ã¿ãŒãã§ãŒã¹ãåäœã決å®ããŸã ã ãã®ç¹ã§ãGoã®ã€ã³ã¿ãŒãã§ãŒã¹ã¯Javaã®ã€ã³ã¿ãŒãã§ãŒã¹ãšå®è³ªçã«éãã¯ãããŸããã
ããšãã°ãJavaã§ã®ã€ã³ã¿ãŒãã§ãŒã¹ãšãã®å®è£ ã¯æ¬¡ã®ãšããã§ãã
public interface Speakable { public String greeting = "Hello"; public void sayHello(); } public class Human implements Speakable { public void sayHello() { System.out.println(Speakable.greeting); } } Speakable speaker = new Human(); speaker.sayHello();
Goã®äŸïŒ
type Speaker interface { SayHello() } type Human struct { Greeting string } func (h Human) SayHello() { fmt.Println(h.Greeting) } ... var s Speaker s = Human{Greeting: "Hello"} s.SayHello()
http://play.golang.org/p/yqvDfgnZ78
äžèŠãéãã¯çŽç²ã«è¡šé¢çãªãã®ã§ãã
- Javaã§ã¯ãããŒã¯ãŒãpublic / protected / etcã䜿çšãããŸããGoã§ã¯ãã¡ãœããåã®æåã®æåãå¯èŠæ§ã決å®ããŸã
- Javaã§ã¯ãå€ãã®å Žåã-ableåŸçœ®èšå·ã䜿çšããŠã€ã³ã¿ãŒãã§ã€ã¹ãåŒã³åºããŸããGoã§ã¯ã-eråŸçœ®èšå·ïŒSenderãReaderãCloserãªã©ïŒã䜿çšããã®ãäžè¬çã§ã
- Javaã§ã¯ãã€ã³ã¿ãŒãã§ã€ã¹ãå®è£ ããããã«ã¯ã©ã¹ã䜿çšãããGoã§ã¯ãã¡ãœãããæã€æ§é ã䜿çšãããŸãã
- Javaã€ã³ã¿ãŒãã§ãŒã¹å®è£ ã§ã¯æ瀺çã«ïŒ implements ïŒãGoã§ã¯æé»çã«ïŒ ããã¯ã¿ã€ãã³ã° ïŒã瀺ãããŸã
- Javaã§ã¯ãã€ã³ã¿ãŒãã§ã€ã¹ãšã¯ã©ã¹ã®äž¡æ¹ã«ããŒã¿ãšã¡ãœããã®äž¡æ¹ãå«ããããšãã§ããŸãããGoã§ã¯ãã€ã³ã¿ãŒãã§ã€ã¹ã«ããŒã¿ãå«ããããšã¯ã§ãããã¡ãœããã®ã¿ãå«ããããšãã§ããŸãã
ãããããããã®éãã®ããã€ããç¹ã«æåŸã®2ã€ã¯éèŠã§ãã ãããã«ã€ããŠè©³ããèŠãŠãããŸãããã
æé»çãªå®è£
ã«ã¢ã®ããã«èŠããã«ã¢ã®ããã«æ³³ããã«ã¢ã®ããã«é³Žããªããããããã«ã¢ã§ãã
Goã§ã¯ãã¡ãœããã宣èšãããšããäºå®ã ãã§ãã¡ãœãããæã€æ§é äœãã€ã³ã¿ãŒãã§ã€ã¹ãæºãããŸãã ããã¯å°ããªããã°ã©ã ã人çºçãªäŸã§ã¯ç¹ã«éèŠã§ã¯ãªãããã§ãããä»ã®ã¯ã©ã¹ã«äœåºŠãç¶æ¿ãããŠããã¯ã©ã¹ãå€æŽããåã«ããèããªããã°ãªããªã倧èŠæš¡ãããžã§ã¯ãã§ã¯éèŠã§ãã
ããŸããŸãªã€ã³ã¿ãŒãã§ã€ã¹ãç°¡åãã€åçŽã«æé»çã«å®è£ ã§ãããããå¯èœãªãã¹ãŠã®ã€ã³ã¿ãŒãã§ã€ã¹ãäºåã«æ€èšããå€éç¶æ¿ã«åãããããšãªããããã°ã©ã ãç°¡åã«æé·ãããããšãã§ããŸãã ããã¯ãGoã倧èŠæš¡ãããžã§ã¯ãã§ã®ç掻ã楜ã«ããããã«èæ¡ãããèšèã§ãã
ããã®éèŠã§ããã«æãããªéãã¯ãæçµçã«ããã°ã©ã ã®ã¢ãŒããã¯ãã£ãæ§ç¯ããæ¹æ³ã§ã-JavaãŸãã¯C ++ã§ã¯ãã»ãšãã©ã®å Žåãæœè±¡ã¯ã©ã¹ãšã€ã³ã¿ãŒãã§ã€ã¹ã宣èšããããšããå§ããŠãç¹å®ã®å®è£ ã«é²ã¿ãŸãã ããã«å¯ŸããŠãGoã§ã¯ãæåã«ç¹å®ã®åãèšè¿°ããããŒã¿ãšã¡ãœãããå®çŸ©ããŸããå®éã«åäœãæœè±¡åããå¿ èŠãããå Žåã«ã®ã¿ ãå¥ã®ã€ã³ã¿ãŒãã§ã€ã¹ãäœæããŸãã ç¹°ãè¿ãã«ãªããŸããããã®éãã®èŠæš¡ã¯ã倧èŠæš¡ãããžã§ã¯ãã§ããæ確ã«ãªããŸãã
ããŒã¿ãšè¡å
Javaã§ã¯ã©ã¹ãšã€ã³ã¿ãŒãã§ãŒã¹ã®äž¡æ¹ãããŒã¿ãšåäœã®äž¡æ¹ãèšè¿°ããå ŽåãGoã§ã¯ãããã®æŠå¿µã¯æ ¹æ¬çã«åºå¥ãããŸãã
æ§é ã¯ããŒã¿ãä¿åããŸãããåäœã¯ä¿åããŸããã ã€ã³ã¿ãŒãã§ã€ã¹ã¯åäœãä¿åããŸãããããŒã¿ã¯ä¿åããŸããã
Hello string
ãªã©ã®å€æ°ãã€ã³ã¿ãŒãã§ã€ã¹ã«è¿œå ããå Žåã¯ãäœãééã£ãããšãããŠããããšãç¥ã£ãŠããå¿ èŠããããŸãã æ§é äœã«ã€ã³ã¿ãŒãã§ã€ã¹ãåã蟌ãå ŽåãåäœãšããŒã¿ãæ··ä¹±ããŸãã Javaã®äžçã§ã¯ããã¯æ£åžžã§ãããGoã§ã¯æœè±¡åã®æ確ãã圢æãããããããã¯éèŠãªåºå¥ã§ãã
äžèšã®äŸã§ã¯ãã¹ããŒã«ãŒã¯åäœã説æããŠããŸããããã®ã€ã³ã¿ãŒãã§ã€ã¹ãå®è£ ãã人ãæ£ç¢ºã«èšãã¹ãããšãèšã£ãŠããŸããã ç¹°ãè¿ãã«ãªããŸãããGoã³ãŒãã®ã€ã³ã¿ãŒãã§ã€ã¹ãšããŠã®Speakerã¯ãHumanã®ç¹å®ã®å®è£ ãèšè¿°ããããããŒã¹ã¯ã©ã¹ããšããŠã§ã¯ãªãã ä»ã®typeã«ãã£ãŠå®è£ ãããå®éçãªå¿ èŠæ§ããçãŸããŸãã ã
ãæ¯ãèãããšãããŒã¿ãã®æœè±¡åãæ確ã«åºå¥ãå§ãããšããã«ãGoã§ã€ã³ã¿ãŒãã§ãŒã¹ã䜿çšããç®çãšé©åãªæ¹æ³ãããæ確ã«ç解ãå§ããããšãç解ããããšãéèŠã§ãã 人éãšè©±è ã¯çŽäº€ããŠããŸãã 人éã¯å¥ã®10åã®ã€ã³ã¿ãŒãã§ã€ã¹ïŒWalkerãListenerãPlayerãProgrammerãªã©ïŒãç°¡åã«æºããããšãã§ããã¹ããŒã«ãŒã¯ä»ã®ããã±ãŒãžïŒãããããåç©ãã³ã³ãã¥ãŒã¿ãŒãªã©ïŒããã§ãæ°åçš®é¡ã«æºè¶³ã§ããŸãã ãããŠãããããã¹ãŠã¯ãæå°éã®æ§æãªãŒããŒãããã§è¡ãããŸãããããã倧èŠæš¡ãªã³ãŒãããŒã¹ã§ã¯éèŠã§ãã
ã€ã³ã¿ãŒãã§ãŒã¹ããã€ã¹
Humanãåæã«ã¹ããŒã«ãŒã«ãªããããã«å€ãã®ã€ã³ã¿ãŒãã§ã€ã¹ã«ãªããšåæã«ãçŽäº€ããæ¹æ³ãç解ããŠããªãå Žåã¯ãããã«æ·±ãæãäžããŠãã€ã³ã¿ãŒãã§ã€ã¹ãããŒãã®äžã«ã©ã®ããã«é 眮ãããŠããããèŠãŠã¿ãŸãããã Go 1.5ïŒããèªäœã¯Goã§èšè¿°ãããŠããŸãïŒã§ã¯ãã€ã³ã¿ãŒãã§ã€ã¹ã¿ã€ãã¯æ¬¡ã®ããã«ãªããŸãã
src /ã©ã³ã¿ã€ã / runtime2.go
type iface struct { tab *itab data unsafe.Pointer }
ããã§ãtabã¯ã€ã³ã¿ãŒãã§ã€ã¹ããŒãã«ãžã®ãã€ã³ã¿ããŸãã¯itableã¯ãã€ã³ã¿ãŒãã§ã€ã¹ãæºããããã«äœ¿çšãããããã€ãã®ã¿ã€ãã¡ã¿ããŒã¿ãšã¡ãœããã®ãªã¹ããæ ŒçŽããæ§é ã§ãã
ããŒã¿-ç¹å®ã®ïŒéçïŒã¿ã€ãã®å®éã®å€æ°ã瀺ããŸãã
æ確ã«ããããã«ã次ã®ããã«ã³ãŒãããããã«å€æŽããŸãã
h := Human{Greeting: "Hello"} s := Speaker(h) s.SayHello()
http://play.golang.org/p/AB0ExdGN0W
ãã®å³ã¯ã sã2ã€ã®ãã€ã³ã¿ãŒã§æ§æãããŠããããšã瀺ããŠããŸããæåã®ãã€ã³ã¿ãŒã¯ç¹å®ã®ãã¢ïŒéçåHumanãã¹ããŒã«ãŒã€ã³ã¿ãŒãã§ã€ã¹ïŒã®itableãæããä»æ¹ã¯Humanã®å ã®å€ã®ã³ããŒãæããŸãã
h := Human{Greeting: "Hello"} s := Speaker(h) h.Greeting = "Meow" s.SayHello() // "hello"
ã€ã¿ãã«
itableã«ã€ããŠå°ã説æããŸãã ãã®ããŒãã«ã¯ãã€ã³ã¿ãŒãã§ã€ã¹ãšéçãªåã®ãã¢ããšã«äžæã§ãããããã³ã³ãã€ã«æ®µéã§ã®èšç®ïŒåæãã€ã³ãã£ã³ã°ïŒã¯éåççã§éå¹ççã§ãã
代ããã«ãã³ã³ãã€ã©ã¯åéçã¿ã€ãã®ã¡ã¿ããŒã¿ãçæããŸããããã«ã¯ããšãããããã®ã¿ã€ãã«å®è£ ãããã¡ãœããã®ãªã¹ããæ ŒçŽãããŸãã åæ§ã«ãã¡ã¿ããŒã¿ã¯ãåã€ã³ã¿ãŒãã§ã€ã¹ã®ã¡ãœããã®ãªã¹ãã§çæãããŸãã ããã§ãããã°ã©ã ã®å®è¡äžã«ãã©ã³ã¿ã€ã Goãç¹å®ã®ãã¢ããšã«itableããªã³ã¶ãã©ã€ã§èšç®ã§ããŸãïŒé 延ãã€ã³ãã£ã³ã°ïŒã ãã®itableã¯ãã£ãã·ã¥ããããããèšç®ãã¹ã¯1åããçºçããŸããã
ãããç¥ã£ãŠãGoãã³ã³ãã€ã«æã«åã®äžäžèŽããã£ããããã®ã¯æããã§ãããå®è¡æã«ã€ã³ã¿ãŒãã§ã€ã¹ã«ãã£ã¹ãããŸãã ã€ã³ã¿ãŒãã§ãŒã¹åãžã®å€æã®ãšã©ãŒãå®å šã«ãã£ããããããã«ãã«ã³ã-okæ§æãååšããããšãå¿ããªãã§ãã ãã-if
if s, ok := h.(Speaker); !ok { ... }
if s, ok := h.(Speaker); !ok { ... }
ã
var s Speaker = string("test") // compile-time error var s Speaker = io.Reader // compile time error var h string = Human{} // compile time error var s interface{}; h = s.(Human) // runtime error
空ã®ã€ã³ã¿ãŒãã§ãŒã¹{}
ããã§ã空ã®ã€ã³ã¿ãŒãã§ã€ã¹ãšåŒã°ãã
interface{}
æãåºããŠã¿ãŸããããããã¯ãã©ã®ã¿ã€ãã§ãäžè¬ã«æºããããŸãã 空ã®ã€ã³ã¿ãŒãã§ãŒã¹ã«ã¯ã¡ãœããããªãã®ã§ããããèšç®ããŠä¿åããå¿ èŠã¯ãããŸãã-éçåã«é¢ããã¡ã¿æ å ±ã§ååã§ãã
ãããã£ãŠãã¡ã¢ãªã§ã¯ã空ã®ã€ã³ã¿ãŒãã§ã€ã¹ã¯æ¬¡ã®ããã«ãªããŸãã
空ã®ã€ã³ã¿ãŒãã§ã€ã¹ã䜿çšãããã³ã«ãèŠããŠãããŠãã ããã ããã¯äœã®æå³ããªãããšã æœè±¡åãªãã ããã¯ãç¹å®ã®ã¿ã€ãã«å¯ŸããèŠããªããã³ãã§ãããç¹å®ã®ã¿ã€ããããªãããé ããåäœãç解ããããšã¯ã§ããŸããã ãã®ãããæã極端ãªå Žåã«ç©ºã®ã€ã³ã¿ãŒãã§ã€ã¹ã䜿çšããå¿ èŠããããŸãã
ã€ã³ã¿ãŒãã§ã€ã¹ãšãžã§ããªãã¯
ãåç¥ã®ããã«ãGoã§ã¯ãæ±çšã³ã³ããã¯èšèªã«ãããã®ïŒã¹ã©ã€ã¹ããããïŒã«ãã£ãŠã®ã¿å¶éãããŸãã Goã¯ãã€ã³ã¿ãŒãã§ã€ã¹ã䜿çšããŠæ±çšã¢ã«ãŽãªãºã ãäœæã§ããŸãã ããã§ã®å€å žçãªäŸã¯ããã®ãããªãã€ããªããªãŒã®å®è£ ã§ã ã
type Item interface { // Less tests whether the current item is less than the given argument. // // This must provide a strict weak ordering. // If !a.Less(b) && !b.Less(a), we treat this to mean a == b (ie we can only // hold one of either a or b in the tree). Less(than Item) bool }
btree.Itemã¿ã€ãã¯ãå€ã®æ¯èŒãå¯èœã«ããåäžã®Lessã¡ãœãããå®çŸ©ãããŠããã€ã³ã¿ãŒãã§ãŒã¹ã§ãã ã¢ã«ãŽãªãºã ã®å éšã§ã¯ãItem-sããã¹ã©ã€ã¹ã䜿çšãããŸããã¢ã«ãŽãªãºã ã¯ãéçåãäœã§ããããæ·±ãæ°ã«ããŸãããå¿ èŠãªã®ã¯ãå€ãæ¯èŒã§ããããšã ãã§ãããããLessïŒïŒã¡ãœããããåŸããããã®ã§ãã
type MyInt int func (m MyInt) Less(than MyInt) bool { return m < than } b := btree.New(10) b.ReplaceOrInsert(MyInt(5))
åæ§ã®ã¢ãããŒãã¯ã sortããã±ãŒãžã®æšæºã©ã€ãã©ãªã§èŠãããšãã§ããŸã-sort.Interfaceã€ã³ã¿ãŒãã§ãŒã¹ãæºããä»»æã®åã¯ããã©ã¡ãŒã¿ãŒãšããŠsort.Sorté¢æ°ã«æž¡ããããœãŒããããŸãïŒ
type Interface interface { // Len is the number of elements in the collection. Len() int // Less reports whether the element with // index i should sort before the element with index j. Less(i, j int) bool // Swap swaps the elements with indexes i and j. Swap(i, j int) }
äŸïŒ
type Person struct { Name string Age int } // ByAge implements sort.Interface for []Person based on // the Age field. type ByAge []Person func (a ByAge) Len() int { return len(a) } func (a ByAge) Swap(i, j int) { a[i], a[j] = a[j], a[i] } func (a ByAge) Less(i, j int) bool { return a[i].Age < a[j].Age } ... people := []Person{ {"Bob", 31}, {"John", 42}, {"Michael", 17}, {"Jenny", 26}, } sort.Sort(ByAge(people))
ã€ã³ã¿ãŒãã§ãŒã¹ã®ä¹±çšãæ¢ããŠç掻ãå§ããæ¹æ³
Goã®å€ãã®æ°åè ãç¹ã«åçåä»ãã䜿çšããèšèªããåãæ¿ãã人ã¯ãã€ã³ã¿ãŒãã§ã€ã¹åã§ç¹å®ã®åã䜿çšããªãæ¹æ³ã確èªããŠããŸãã ããã¹ãŠãã€ã³ã¿ãŒãã§ã€ã¹{}ã§ã©ããããŸãããšãéçºè ã¯èããŠãã»ãšãã©ã®å Žåã¯ç©ºã®ã€ã³ã¿ãŒãã§ã€ã¹ã§ããã°ã©ã ãæ±æããŸãã
ããããããã§ã®é»éã®ã«ãŒã«ã¯æ¬¡ã®ããã«èãããŸããåžžã«ç¹å®ã®ã¿ã€ãã§åäœããå¿ èŠãªå Žåã«ã®ã¿ã€ã³ã¿ãŒãã§ã€ã¹ã䜿çšããããã§ãªãå Žåã¯æã極端ãªå Žåã¯ç©ºã®ã€ã³ã¿ãŒãã§ã€ã¹ã䜿çšããŸãã
ããšãã°ãããŒã¿ã衚瀺ããããã·ã¥ããŒããäœæããŸãããã®ããŒã¿ã¯ã1ã€ã®ãœãŒã¹ããã¯float64å€ã®åœ¢åŒã§ãå¥ã®ãœãŒã¹ããã¯æååïŒã倱æãããæåããªã©ïŒã®åœ¢åŒã§ååŸãããŸãã ãã£ã³ãã«ãä»ããŠå€ãåãåããããããç»é¢ã«è¡šç€ºããé¢æ°ãã©ã®ããã«å®è£ ããŸããïŒ
ã»ãšãã©ã®åå¿è ã¯èšãã§ããã-ç°¡åã§ãã空ã®ã€ã³ã¿ãŒãã§ãŒã¹ïŒ
chan interface{}
ïŒã®ãã£ãã«ãäœæãããããééãããŠãããåã«ãã£ã¹ãããŸãããïŒ
func Display(ch chan interface{}) { for v := range ch { switch x := v.(type) { case float64: RenderFloat64(x) case string: RenderString(x) } } }
ãããŠããã®ãããªã³ãŒãã«ã¯ååšããæš©å©ããããŸãããããçŸããè¡ãããšãã§ããŸãã ç§ãã¡ã®å Žåãfloat64ãšstringã®å ±éç¹ã«ã€ããŠèããŠã¿ãŸãããã äž¡æ¹ãã¬ã³ããªã³ã°ããå¿ èŠããããšããäºå®ã¯ãRenderã¡ãœããã§ã€ã³ã¿ãŒãã§ãŒã¹ãäœæããããã®åè£ã§ãã è©ŠããŠã¿ãŸãããïŒ
type Renderer interface { Render() }
ããã«ãã¡ãœãããæšæºåã«ã¢ã¿ããã§ããªãããïŒããã¯æ¢ã«å¥ã®åã«ãªããŸãïŒãMyFloatãšMyStringãäœæããŸãã
type ( MyFloat float64 MyString string )
ãããŠãããããã«Renderã¡ãœãããå®è£ ããRendererã€ã³ã¿ãŒãã§ã€ã¹ãèªåçã«æºãããŸãã
func (f MyFloat) Render() { ... } func (s MyString) Render() { ... }
ããã§ã
Display
é¢æ°ã¯æ¬¡ã®ããã«ãªããŸãã
func Display(ch chan Renderer) { for v := range ch { v.Render() } }
ãã£ãšçŸããç°¡æœã§ãããïŒ ããã§ãDisplayã§ã¬ã³ããªã³ã°ã§ããããã«ããå¿ èŠãããå¥ã®ã¿ã€ããè¿œå ããå ŽåãRenderã¡ãœãããè¿œå ããã ãã§ãä»ã«å€æŽããå¿ èŠã¯ãããŸããã
ãããŠãéèŠãªããšã¯ããã®ã³ãŒãã¯ç©äºã®å®éã®ç¶æ ãåæ ããŠããŸã-ã€ã³ã¿ãŒãã§ãŒã¹ã®åã®äžã§åããããã®äžè¬çãªæ¯ãèãã«åŸã£ãŠçµåããŸãã ãã®åäœã¯ããŒã¿èªäœã«çŽäº€ããŠãããçŸåšã§ã¯ã³ãŒãã«åæ ãããŠããŸãã
ã€ã³ã¿ãŒãã§ãŒã¹ãµã€ãº
Go Proverbsã®ä¿¡æ¡ã¯æ¬¡ã®ãšããã§ãã ãã€ã³ã¿ãŒãã§ã€ã¹ã倧ãããªãã»ã©ãæœè±¡åã匱ããªããŸãã ã äžèšã®äŸã§ã¯ãã¡ãœããã1ã€ã ãã®å°ããªã€ã³ã¿ãŒãã§ã€ã¹ã¯ããã¬ã³ããªã³ã°ãããå€ãã®æœè±¡åãéåžžã«æ確ã«èª¬æããã®ã«åœ¹ç«ã¡ãŸããã ããšãã°ãæååã«åºæã®äžé£ã®ã¡ãœããã䜿çšããŠã€ã³ã¿ãŒãã§ã€ã¹ãäœæããå Žåãfloat64ã§ããã䜿çšããããšã¯ã§ãããæ°ãããã®ãèãåºãå¿ èŠããããŸãã
Goã§ã¯ãã»ãšãã©ã®ã€ã³ã¿ãŒãã§ã€ã¹ã«1-2ã¡ãœãããå«ãŸããŠããŸãã ããããããã¯ãã¡ããçŠæ¢ã§ã¯ãããŸãã-äœçŸãã®ã¡ãœãããåããã€ã³ã¿ãŒãã§ã€ã¹ã絶察ã«å¿ èŠãªå ŽåïŒããšãã°ãäžéšã®ã¢ãã¯åãïŒ-ãããåé¡ãããŸããã
誰ãšãã€ã€ã³ã¿ãŒãã§ãŒã¹ãäœæããå¿ èŠããããŸããïŒ
èå³æ·±ãè°è«ããããŸãããããã®éã«æ¬¡ã®ãããªå£°æãåºãããŸãã- ãGoã®ãã¹ãŠã®ã©ã€ãã©ãªã¯ã€ã³ã¿ãŒãã§ã€ã¹ããšã¯ã¹ããŒãããå¿ èŠããããŸã ã ã ããšãã°ãã©ã€ãã©ãªæ©èœãã¢ãã¯ãããå Žåã¯ããã®ã€ã³ã¿ãŒãã§ã€ã¹ãã¹ã¿ãã«å®è£ ããŠãã¹ãããã ãã§ååã§ãã
ããã§ã¯ãããŸããã åã©ã€ãã©ãªã¯ã€ã³ã¿ãŒãã§ãŒã¹ããšã¯ã¹ããŒããã¹ãã§ã¯ãªãã誰ãã€ã³ã¿ãŒãã§ãŒã¹ãäœæãããã決å®ããããã®äžè¬çãªã«ãŒã«ã¯æ¬¡ã®ããã«èª¬æã§ããŸãã
ã€ã³ã¿ãŒãã§ã€ã¹ã¯ããããã¥ãŒãµãŒã§ã¯ãªããã³ã³ã·ã¥ãŒããŒã«ãã£ãŠäœæãããŸãã
ã©ã€ãã©ãªãStaticType1ãå®è£ ããŠããå Žåããã®ããã®ã€ã³ã¿ãŒãã§ã€ã¹ãäœæããå¿ èŠã¯ãããŸããã ã©ã€ãã©ãªã®ã³ã³ã·ã¥ãŒããšããŠãåã®åäœãæœè±¡åããããã¯ããŠStaticType2ãäœæããå Žåã¯ãã³ãŒãå ã§StaticType1ãšäº€æå¯èœã«ããå¿ èŠããããŸããèªåã§Interfaceãå®è£ ããèªåã§äœ¿çšããŸãã ããã¯ããªãã®ä»äºã§ã-ããªãã¯èšèªã§ããã解決ããŸãã
äžèšã®ãœãŒãã©ã€ãã©ãªã§ã¯ãsort.Sorté¢æ°ãæ©èœããããã«sort.Interfaceã€ã³ã¿ãŒãã§ã€ã¹ãå¿ èŠã§ããã€ãŸããã©ã€ãã©ãªèªäœããã®ã³ã³ã·ã¥ãŒãã§ãã
ãŸãšã
Goã¿ã€ãã·ã¹ãã ã¯ãä»ã®èšèªããåãæ¿ãããšãã«ããã®åçŽãã®ç¹ã§äŸç¶ãšããŠããã€ãã®åé¡ãåŒãèµ·ãããŸãã 誰ãããããSOLIDååã«è©°ã蟌ãããšããŠããã誰ããã¯ã©ã¹ãšã®é¡äŒŒæ§ãæ§ç¯ããããšããŠããã誰ããç¹å®ã®åãæªã§ããããžã§ããªãã¯åãè¯ããšèããŠãããããã¯åå¿è ã«ãšã£ãŠããã€ãã®å°é£ãçã¿åºããŸãã ããããããã¯æ£åžžã§ãããã»ãšãã©ãã¹ãŠããããééããã®ã§ããã®èšäºã§Goã®ã€ã³ã¿ãŒãã§ãŒã¹ã®æ¬è³ªãç®çãç®çãå°ãæããã«ããŠã»ãããšæããŸãã
èŠçŽãããšã3ã€ã®ãã€ã³ãïŒ
- ã€ã³ã¿ãŒãã§ã€ã¹ã¯åäœãå®çŸ©ããéçåã¯ããŒã¿ãå®çŸ©ããŸã
- ã€ã³ã¿ãŒãã§ãŒã¹ã倧ããã»ã©ãæœè±¡åã匱ã
- ã€ã³ã¿ãŒãã§ã€ã¹ã¯éåžžãæ¶è²»è ã«ãã£ãŠäœæãããŸãã