标签: introspection

为什么没有办法在Objective C中使用对象进行内省?

我已经看到了调用可怕的C函数和获取必须迭代的结构的示例(特别是这里),充满了大量的underbars.

为什么我不能这样做(伪跟随):

  Money *cost = [[Money alloc] init];

  for (Property *property in [[cost class] properties]){
    ..
  }

  for (Method *method in [[cost class] methods]){
    ..
  }
Run Code Online (Sandbox Code Playgroud)

reflection introspection objective-c

0
推荐指数
1
解决办法
954
查看次数

如何使用java bean的参数化属性名称和类型的lis

说我有一个豆子

public class SomeBean{
     List<String> messages;
     List<Integer> scores;
     String id;
     int  number;
Run Code Online (Sandbox Code Playgroud)

....}

我使用以下代码来处理或转储propreties

        BeanInfo beanInfo = Introspector.getBeanInfo(beanClass, Object.class);
        PropertyDescriptor descriptors[] = beanInfo.getPropertyDescriptors();
        int stop = descriptors.length;
        for (int i = 0; i < stop; ++i) {
            PropertyDescriptor descriptor = descriptors[i];
            logger.info(descriptor.getName() + " : " + descriptor.getPropertyType().getName() + ", writemethod :" + descriptor.getWriteMethod());

        }
Run Code Online (Sandbox Code Playgroud)

我希望能够获得"分数"和"消息"的参数化类型.当我破坏代码时,"descriptor.getPropertyType().getName()"的值对于消息和分数都是"java.util.List".

如何判断"消息"的属性描述符是否指的List<String>是"分数"是指List<Integer>

java generics reflection introspection propertydescriptor

0
推荐指数
1
解决办法
3328
查看次数

"不能转换为java.lang.Class",即:哪个类型不是类

这可能看起来是一个愚蠢的问题(因为它可能是特定于项目的),但在这种情况下它足够普遍:

我正在运行一段代码,它给出了ClassCastException我写的标题错误信息.这里所提到的转换是从类型的对象java.lang.reflect.TypeClass<?>.

除了原始类型,Java中哪种类型不是类?

谢谢你的回答

java introspection

0
推荐指数
1
解决办法
3478
查看次数

比较[类]不起作用?

我有一个单元测试:

- (void)testFetchTrackByTrackIdIsATrack
{
    [self addTrackWithSongId:@"123"];
    Track *fetchedTrack = [self.library trackByTrackId:@"123"];
    assertThat(fetchedTrack, instanceOf([Track class]));
}
Run Code Online (Sandbox Code Playgroud)

哪个失败了:

file:///Users/elliot/Development/Hark/HarkTests/TestLibrary.m: test failure:
-[TestLibrary testFetchTrackByTrackIdIsATrack] failed: Expected an instance
of Track, but was Track instance <Track: 0x6180001077d0>
Run Code Online (Sandbox Code Playgroud)

我有几个其他测试使用相同的实例检查不同的类工作 - 但我无法锻炼为什么这不起作用.深入研究:

- (void)testFetchTrackByTrackIdIsATrack
{
    [self addTrackWithSongId:@"123"];
    Track *fetchedTrack = [self.library trackByTrackId:@"123"];
    Class c1 = [fetchedTrack class];
    Class c2 = [Track class];
}
Run Code Online (Sandbox Code Playgroud)

调试器报告:

c1  Class   Track           0x0000000100012fe0
c2  Class   0x1000b3eb8     0x00000001000b3eb8
Run Code Online (Sandbox Code Playgroud)

注意它怎么看不到那[Track class]是一类Track?当我将这个相同的逻辑应用于其他传递的单元测试时,它们都会报告正确的类名.

感觉它在运行时没有类元数据,但为什么呢?

还有一些案例:

assertTrue(c1 == c2);                                   // FAIL
assertThat([fetchedTrack …
Run Code Online (Sandbox Code Playgroud)

unit-testing introspection objective-c ochamcrest

0
推荐指数
1
解决办法
184
查看次数

如何在函数内部获取函数对象(Python)

我希望有类似的东西

def x():
  print get_def_name()
Run Code Online (Sandbox Code Playgroud)

但不一定知道的名字x.

理想情况下,它将返回'x'x将是函数的名称.

python function introspection python-2.7

0
推荐指数
2
解决办法
3052
查看次数

在 Tcl 中查找命名空间的所有过程

让我们说我有一个命名空间。我想找到所有的命名空间过程。例如,假设我有以下代码:

namespace eval foo { 
   proc me {} { puts "yey!" }
   proc moo {} { puts "ney!" }
}
puts [ getAllNamespaceProcs foo ] ; # getAllNamespaceProcs is what I do not know how to do
Run Code Online (Sandbox Code Playgroud)

这应该产生:

> { me moo }
Run Code Online (Sandbox Code Playgroud)

谢谢。

namespaces introspection tcl proc

0
推荐指数
1
解决办法
532
查看次数

Can I get all attributes that were defined in the __init__ method of a class?

Suppose I have a class like this:

class A:
    def __init__(self):
        self.a = "a"
        self.b = "b"
Run Code Online (Sandbox Code Playgroud)

How would I get a dictionary like this ?

{"a": "a", "b": "b"}
Run Code Online (Sandbox Code Playgroud)

I read this question and answers, but the dictionary in these answers always contains some "dunder" attributes as well, which I never defined in A.__init__. Will I have to use one of the solutions in the linked question and filter out the dunder attributes, or is there a …

python attributes class introspection python-3.x

0
推荐指数
1
解决办法
41
查看次数