Questions tagged [reflect]
123 questions
3
votes
1 answer
C# Why cannot get the correct instance from ioc, when i use reflect to regist class
I want to register classes from a dll to IOC, but when I get the instance from the IOC, it returns me a null value. As the code below Version_2.
But if I use the Version_1, it will return a correct instance.
the code as below:
private static…

Ryan.Ukule
- 45
- 1
- 5
3
votes
1 answer
How to assign value into reflect Field()?
I faced such a problem.
I need to compare two structure if they type and name of field is equal.
To assign value from sour to dist. I write some code, but here I can assign reflect.Field() value. Could you help me? And I create the test in the…

Aibaend
- 67
- 2
- 12
3
votes
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
- 31
- 1
- 1
- 2
3
votes
0 answers
If a KParameter.isOptional = true, how can I get the default value?
My class:
data class TestMockModel(val age: Int = 3)
How can I get the age's default value by age's KParameter?
such
val ageKParameter = TestMockModel::class.parameters[0]
How can I get the default value by ageKParameter

imuto
- 51
- 2
3
votes
1 answer
JSON marshal of slice made from reflect.New() gives null in golang
I'm using reflect in golang to make a new initialized slice. But the moment I json.Marshal this new reflected slice, I get a JSON null value instead of a []. See this example here where I compare two cases:
package main
import (
…

John
- 32,403
- 80
- 251
- 422
2
votes
0 answers
Creating an object with methods using reflect results in segmentation violation
I'm to create an object (whatever it is) satisfying certain interface dynamically. Current reflect.StructOf creates structs but without adding methods. So I read the source code and tried to add a function in reflect package and I got the following…

march1993
- 133
- 1
- 7
2
votes
0 answers
Wrap a reflect.Value with pointer which points to the same element
Here I found the following code -
// ptr wraps the given value with pointer: V => *V, *V => **V, etc.
func ptr(v reflect.Value) reflect.Value {
pt := reflect.PtrTo(v.Type()) // create a *T type.
pv := reflect.New(pt.Elem()) // create a…

Nimrod Fiat
- 473
- 3
- 12
2
votes
1 answer
Go dynamically instantiating struct by name at runtime via reflection
Is there anything equivalent in Go to the dynamic Class instantiation capabilities provided by languages like Java (note: requisite exception handling logic has been omitted here for the sake of brevity):
Class cls =…

Giles Thompson
- 1,097
- 1
- 9
- 24
2
votes
2 answers
Kotlin Access Property Name from Delegate
I'm writing a saving system for my game using kotlin delegated properties.
Here is a small example
import kotlin.reflect.KProperty
object Test {
val test: Int by no_prop { 10 } // I want this
val testTwo: Int by prop(::testTwo) { 10 } // I…

Jonathan Beaudoin
- 2,158
- 4
- 27
- 63
2
votes
2 answers
SQLAlchemy: reflecting tables of existing database not working properly
I am currently engaged in evaluating SQLAlchemy for a new project. When trying to reflect the tables of an existing database (postgres, oracle), I am encountering some issues.
In order to connect to an Oracle database the following code is being…

user4338
- 173
- 1
- 12
2
votes
1 answer
How to check reflect.Value is nil or not?
I have this code:
package main
import (
"fmt"
"reflect"
)
type cmd struct{
Echo func(string) (string,error)
}
func main() {
cmd := cmd{
Echo : func(arg string) (string, error) {
return arg, nil
},
…

Zouglou
- 89
- 1
- 11
2
votes
0 answers
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
- 99
- 7
2
votes
1 answer
Using reflect, how to set value to a struct field (pointer)
I try to set value to a struct field (pointer field) by reflect, but failed.
I get the name of a struct field, so use FieldByName to get the field
The field is a pointer.
I try to use FieldByName().Set FieldByName().SetPointer to set…

wusuoweimain
- 21
- 1
- 2
2
votes
1 answer
Exception in thread "Thread-0" java.lang.reflect.InaccessibleObjectException
Trying to run server and client on my java project which consists of a boardgame made in CLI and GUI. Unfortunately I'm ending up in this error after adding username:
Exception in thread "Thread-0" java.lang.reflect.InaccessibleObjectException:…

Lol
- 77
- 1
- 1
- 9
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…

alexandremoraes
- 59
- 1
- 8