FAQ
Hi fellow gophers,

Sorry if I sound very ignorant, I'm not a full time developer. I'm sure
somebody must already thought about this. But can we do this:

type Number union {
     int
     float32
}

func (n Number) Max(m Number) Number {
     if n.(type) == int && m.(type) == int{
         if n.(int) > m.(int) {
             return n
         }
         return m
     }
     if float32(n) > float32(m) {
         return n
     }
     return m
}

func main() {
     var a int = 1
     var b float32 = 2
     fmt.Println(Number(a).Max(b))
}

Although it's not very clean, but I think it should have compile time
checks?
--
Jackie

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

Discussion Posts

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 1 of 9 | next ›
Discussion Overview
groupgolang-nuts @
categoriesgo
postedJul 26, '13 at 9:22a
activeJul 26, '13 at 6:32p
posts9
users4
websitegolang.org

People

Translate

site design / logo © 2021 Grokbase