FAQ
var typeOfError = reflect.TypeOf(error(nil))
should work also
On Friday, May 25, 2012 11:54:51 PM UTC+8, Petar Maymounkov wrote:

Got it. I saw this in rpc/server.go:

// Precompute the reflect type for error. Can't use error directly
// because Typeof takes an empty interface value. This is annoying.
var typeOfError = reflect.TypeOf((*error)(nil)).Elem()

This is how you do it. Not straightforward, but it's ok :)

P


On Friday, May 25, 2012 11:52:27 AM UTC-4, Petar Maymounkov wrote:

I hope I am not missing something obvious here:

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

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

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.

Thanks
--
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

  • David Symonds at Mar 20, 2013 at 11:38 pm

    On Thu, Mar 21, 2013 at 2:07 AM, wrote:

    var typeOfError = reflect.TypeOf(error(nil))
    should work also
    That doesn't work. You can't store an interface value in another
    interface value, so the reflect package will only see a nil
    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.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedMar 20, '13 at 7:21p
activeMar 20, '13 at 11:38p
posts2
users2
websitegolang.org

2 users in discussion

Farproc: 1 post David Symonds: 1 post

People

Translate

site design / logo © 2022 Grokbase