Questions tagged [reflect]

103 questions
1
vote
2 answers

Boolean.FALSE not equal to false

So I was playing with java.lang.reflect stuff and tried to make something like this. And here is my problem (maybe a bug): The code for my method to set the field to true: private static void setFinalStatic(Field field, Object newValue) throws…
32byTe
  • 23
  • 4
1
vote
1 answer

I receive an Exception When reflecting java interface

I want to reflect an interface in one of my SDK and call it, but I received an exception. The following is my code. Please help me solve this problem public class ReflectMain { Class obs = null; InterProxy.ProxyCallback callback = new…
0
votes
1 answer

Determine with reflect if struct field is incomplete Cgo type

I have some generic code that uses reflection to handle struct fields. These fields may or may not include C types, referenced through Cgo. One problem I encountered was that those aforementioned C types may be "incomplete structs", for instance:…
robbieperry22
  • 1,134
  • 10
  • 35
0
votes
1 answer

Is there a way to use reflect to discern type-relationships in Go?

Context Writing a URL Query Parameter parser for Go language library Problem Only structs have a form of inheritance in Go, that I am aware of. One can use the reflect package to discern the kind of an entity, i.e. it's fundamental storage class…
Mordachai
  • 8,657
  • 4
  • 52
  • 96
0
votes
0 answers

Go Reflection - Dynamic Type with Methods

Using Go's reflect package, you can create dynamic struct types using reflect.StructOf(): typ := reflect.StructOf([]reflect.StructField{ { Name: "Height", Type: reflect.TypeOf(float64(0)), Tag: …
Jordan
  • 1,905
  • 8
  • 33
  • 58
0
votes
0 answers

Get the underlying type from a string in go?

If I have a string, e.g. "api.Client", and I want the actual golang type from that, which I know exists, how can I do this? I have scanned the reflect package and couldn't find anything, reflect.TypeOf("api.Client") will of course return…
transient_loop
  • 5,144
  • 12
  • 46
  • 95
0
votes
0 answers

It is possible to reflect the method caller in golang?

package main import ( "fmt" ) type S struct { } func (s *S) Ping() { fmt.Println("Pong") } func main() { s := &S{} Do(s.Ping) } func Do(f func()) { // somehow reflect main.S by f Or maybe other ways to do it? } Here is the…
0
votes
1 answer

reflect.DeepEqual() is returning false but slices are same

I am comparing two slices, both of type []int. One is coming in to API in the form of json and parsed as go struct. In the struct, it is intialized as empty []int{}. Second is saved in the database (MongoDb) and is fetched and mapped to same struct…
Amandeep kaur
  • 533
  • 1
  • 7
  • 20
0
votes
2 answers

Cs50 pset4 reflect image filter code problem

I'm working on the cs50 pset4 exercise filter, and I finished the grayscale filter and the sepia filter, and now I'm on the reflect filter. I'm supposed to reflect this image horizontally: NORMAL But all I get is this: REFLECT I don't know what's…
Lost in code
  • 145
  • 1
  • 10
0
votes
1 answer

How to realistically reflect a 3d sphere in Unity with C#

I've been trying to realistically reflect a 3d sphere on the walls of a box for a while now in Unity. For some reason, the reflection is generally correct, but when the ball hits a wall in certain directions, the reflection is incorrect. To…
BugDoctor1
  • 11
  • 4
0
votes
0 answers

By using a string like 'List', how can I get its class, just like classForName("List")?

I want to execute a method by using reflect, the method has a parameter which is a List type, and the list type is not stable, maybe List《String》, List《someClass》. ect.
JokerSora
  • 1
  • 1
0
votes
1 answer

Generic unmarshalling in Go

I'm trying to figure out if there is a way to unmarshal JSON strings to a specific struct, using only the string and the intended type. Here is what I have come up with so far. Code package main import ( "encoding/json" "fmt" …
user18247
  • 31
  • 3
0
votes
1 answer

Transform struct to slice struct

I'm trying to select a struct by string input and then depending on the return JSON Object or Array, unmarshall the JSON. Is it correct to think of a way to reflect the struct to slice struct? if so how to do that with…
0
votes
3 answers

JSON Unmarshal does not work with dynamic struct created by relect

I'm trying to parse JSON files by using dynamically created structs, but apparently I'm doing something wrong. Can somebody please tell we what am I doing wrong here: structured := make(map[string][]reflect.StructField) structured["Amqp1"] =…
paramite
  • 33
  • 1
  • 6
0
votes
1 answer

Create List by Type variable

I want to create a list which has a generic type that is not constant. The best way to write the problem down is this: public List createListByType(Type myType) { return new ArrayList(); } Since the code above does not work I need a…
CoralWombat
  • 107
  • 1
  • 3
  • 9