sometimes you don't have the value only a reflect.Type
On Tuesday, May 29, 2012 10:44:42 PM UTC+2, Carlos Castillo wrote:

Um.. under the column of "missing something obvious", since the interface
type you are comparing it to is KNOWN, is there a reason why you can't:

type T interface {

// Let the compiler handle it
func fn (arg T) {

Or if you are making a function that takes different sets of parameters:

type U interface {

// Use a type switch
func fn2 (arg interface{}) {
switch v := arg.(type) {
case T: v.DoSomething()
case U: v.DoSomethingElse()

// Use type assertions
func fn3 (arg interface{}) {
if t, ok := arg.(T) ; ok {
if u, ok := arg.(U) ; ok {

Unless of course, you are using values to which you don't know the types
you want to check. (You did say "known interface X")
On Friday, May 25, 2012 8:52:27 AM UTC-7, Petar Maymounkov wrote:

I hope I am not missing something obvious here:

I am reflect/inspecting the types of the arguments passed to some

I need to verify that the first argument is of type some known interface

I am holding the reflect.Type of the argument. And I need to create a
reflect.Type for the interface X,
so that I can compare them.

The problem = I cannot see how to get the reflect.Type of an interface.

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

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
postedApr 17, '13 at 4:13a
activeApr 17, '13 at 4:13a

1 user in discussion

Hraban Luyat: 1 post



site design / logo © 2022 Grokbase