Questions tagged [reflect]

103 questions
2
votes
1 answer

How to iterate through *T funcs from struct over reflect.TypeOf(interface{})?

I'm having a few problems iterating through *T funcs from a struct using reflect. I've searched a lot of answers but none seems to talk specifically about this situation. I've found a reflect.NewAt at golang documentation but to be honest I didn't…
2
votes
1 answer

Ignore case in golang reflection FieldByName

I am trying read from a struct using reflection in golang which I was able to do successfully but I am wondering what can I do to ignore case of a field name. I have the below code type App struct{ AppID string Owner string …
DoIt
  • 2,788
  • 7
  • 38
  • 78
2
votes
1 answer

Eslint not recognizing Reflect

I'm using Reflect in my code. Problem is Eslint thinks its an undeclared variable. I'm getting this error: eslint --config ./.eslintrc.json src 30:25 error 'Reflect' is not defined no-undef 32:9 error 'Reflect' is not defined no-undef 39:21 …
Robert Biggs
  • 323
  • 2
  • 8
1
vote
0 answers

How to inpect Async/Promise using Reflect.getMetadata

I found this bug when i'm testing https://github.com/ztytotoro/rxjs-extension/blob/master/src/decorators.ts#L20 export const AsyncFunction = async function () {}.constructor; export function isAsyncOrPromise(fn: any): boolean { return fn…
1
vote
0 answers

how to using reflect to create parametric entity

package main import ( "fmt" "reflect" ) type Aservice struct { } type Adata struct { msg string } type Bdata struct { more string } var amap map[string]interface{} = make(map[string]interface{}, 1024) func (aser *Aservice)…
AM031447
  • 331
  • 1
  • 3
  • 16
1
vote
1 answer

Get value of pointer of a struct field using reflect

package main import ( "fmt" "reflect" ) type PetDetails struct { Name *string } type Student struct { Fname string Lname string City string Mobile *int Pet *PetDetails } func main() { i := 7777777777 …
nanakondor
  • 429
  • 4
  • 10
1
vote
2 answers

panic: reflect: call of reflect.Value.FieldByName on interface Value

I have a variable of type interface{} and I want to change the value of a field using reflection. How can I do it? Variable must be of type interface{} due to other requirements. If the variable isn't of type interface{} all works, otherwise code…
qwerzxcv
  • 29
  • 2
1
vote
1 answer

Reflection struct field.Set with a Flag pointer value

I have a bunch of flags parsed, and I'm then trying to assign those values to fields in a struct, but I'm struggling to get a parsed flag value set into the struct because I can't type assert it or cast it. Here is a snippet of the code I have. It's…
Integralist
  • 5,121
  • 3
  • 21
  • 34
1
vote
0 answers

How to check if a (type variable) Class is implementing the Interface SomeInterface> Java Refect

I'm working with JSON data and converting it into Java Pojo class, then I built an interface like this: public interface DataUtil> { default T someDefaultFn() { ... }; } And I used this interface for some POJO data class…
1
vote
1 answer

How to get a function parameter types

I am able to get a method's parameter types easily with ReflectAPI: Reflect.getMetadata('design:paramtypes', target, propertyKey); but, when I try to get a function's parameter types it is always returning undefined. I have tried to do with these…
user7626079
1
vote
1 answer

How to use type assertion from interface reflection in golang?

I am trying to use type assertion in golang. with direct assertion there is no problem. a, ok := i.(MyStruct) but when I use reflection b, ok := i.(reflect.TypeOf(i)) I got an error. What was a problem with that? and How to deal with it? Full…
Night Owl
  • 59
  • 5
1
vote
1 answer

How do I read the value of a pointer to a slice using reflect?

package main import ( "fmt" "reflect" ) func main() { type tu struct { N int } type t struct { ARRAY []tu NESTED *tu NESTED_ARRAY []*tu } var n = t{[]tu{{4}}, &tu{5}, []*tu{{6}}} …
Jadow
  • 13
  • 2
1
vote
2 answers

reflect runtime error: call of reflect.flag.mustBeAssignable on zero Value

I'm testing this code snippet on go playground, I aim to use reflect to get fields from one object, and then set value to another object package main import ( "fmt" "reflect" ) type T struct { A int `json:"aaa" test:"testaaa"` B…
Troskyvs
  • 5,653
  • 3
  • 23
  • 71
1
vote
2 answers

Method threw 'java.lang.StackOverflowError' exception. Cannot evaluate com.sun.proxy.$Proxy0.toString()

I am using JDKProxy to implement mybatis, but I have a question I have no code with proxy.toString() public class BootStrap { public static void start(){ MySqlSession sqlSession = new MySqlSession(); TestMapper testMapper =…
dc p
  • 11
  • 1
  • 2
1
vote
0 answers

How to generate Function1 by parameter Class and return Class

I want to register a scala Object Method into spark udf. Now i get the MethodMirror by scala reflect and Parameter by java reflect. But i cannot generate a Function object used to register into spark.udf. Such as: object ArrayUdfs { def…
Wozipa
  • 11
  • 2