Questions tagged [introspection]

A capability of some object-oriented programming languages to determine the type of an object at runtime.

Some OOP languages providing Type Introspection ability : Ruby, Objective-C, C++, Java, PHP, Perl, Python, Object Pascal, Actionscript (as3)

The introspection is done differently, depending on the form of program, it is performed upon: inspecting a source code or compiled byte-code is called compile-time introspection, while inspecting properties of running code is a run-time introspection.

For example, Java supports both types of introspection: users of run-time introspection typically perform it via , while compile-time introspection can be implemented with tools or .

http://en.wikipedia.org/wiki/Type_introspection

1021 questions
66
votes
1 answer

Java introspection and reflection

Can any one explain the use of Java reflection and introspection? When we need to use both?
RKCY
  • 4,095
  • 14
  • 61
  • 97
65
votes
3 answers

What is the difference between introspection and reflection?

Can anyone explain from a language/environment agnostic perspective the difference between these two notions? Also is there a set of conditions that programming languages need to satisfy in order to be reflective and/or introspective? And if there…
U r s u s
  • 6,680
  • 12
  • 50
  • 88
61
votes
7 answers

How to check if an object is an instance of a namedtuple?

How do I check if an object is an instance of a Named tuple?
Sridhar Ratnakumar
  • 81,433
  • 63
  • 146
  • 187
56
votes
19 answers

How can I get the name of an object?

Suppose I have code like: x = 0 y = 1 z = 2 my_list = [x, y, z] for item in my_list: print("handling object ", name(item)) # <--- what would go instead of `name`? How can I get the name of each object in Python? That is to say: what could I…
Nathan Fellman
  • 122,701
  • 101
  • 260
  • 319
52
votes
6 answers

How do you get all classes defined in a module but not imported?

I've already seen the following question but it doesn't quite get me where I want: How can I get a list of all classes within current module in Python? In particular, I do not want classes that are imported, e.g. if I had the following module: from…
Davy8
  • 30,868
  • 25
  • 115
  • 173
46
votes
2 answers

How do I get the public methods of a class without inherited methods?

Given any object I can call #public_methods and see all the methods it will respond to. However, I find it would sometimes be handy to get a quick list of all the public methods that are not inherited, i.e. the stuff that's really part of this…
Andrew
  • 42,517
  • 51
  • 181
  • 281
46
votes
7 answers

Java introspection: object to map

I have a Java object obj that has attributes obj.attr1, obj.attr2 etc. The attributes are possibly accessed through an extra level of indirection: obj.getAttr1(), obj.getAttr2(), if not public. The challenge: I want a function that takes an object,…
Radim
  • 4,208
  • 3
  • 27
  • 38
45
votes
2 answers

Why does Ruby use respond_to? instead of responds_to?

I'm curious why Ruby's introspection related method to check if an object responds to a method is respond_to? instead of responds_to? It always seems awkward to me but maybe that's because I'm used to respondsToSelector in objective-c.
Nick
  • 8,483
  • 10
  • 46
  • 65
44
votes
5 answers

How do I list available methods on a given object or package in Perl?

How do I list available methods on a given object or package in Perl?
Benoît
  • 3,355
  • 2
  • 29
  • 34
44
votes
4 answers

Get all methods of an Objective-C class or instance

In Objective-C I can test whether a given class or instance responds to certain selectors. But how can query a class or instance for all its methods or properties of a class (e.g. a list of all methods or properties)?
Georg Fritzsche
  • 97,545
  • 26
  • 194
  • 236
41
votes
8 answers

How can I determine the type of a generic field in Java?

I have been trying to determine the type of a field in a class. I've seen all the introspection methods but haven't quite figured out how to do it. This is going to be used to generate xml/json from a java class. I've looked at a number of the…
Ruan Mendes
  • 90,375
  • 31
  • 153
  • 217
40
votes
6 answers

Inspect python class attributes

I need a way to inspect a class so I can safely identify which attributes are user-defined class attributes. The problem is that functions like dir(), inspect.getmembers() and friends return all class attributes including the pre-defined ones like:…
Jakob Simon-Gaarde
  • 443
  • 1
  • 4
  • 6
39
votes
9 answers

Introspection to get decorator names on a method?

I am trying to figure out how to get the names of all decorators on a method. I can already get the method name and docstring, but cannot figure out how to get a list of decorators.
Tony
  • 2,037
  • 3
  • 22
  • 22
39
votes
7 answers

How do you list the currently available objects in the current scope in ruby?

I'm new to ruby and I'm playing around with the IRB. I found that I can list methods of an object using the ".methods" method, and that self.methods sort of give me what I want (similar to Python's dir(builtins)?), but how can I find the methods of…
monkut
  • 42,176
  • 24
  • 124
  • 155
38
votes
6 answers

Fastest/One-liner way to list attr_accessors in Ruby?

What's the shortest, one-liner way to list all methods defined with attr_accessor? I would like to make it so, if I have a class MyBaseClass, anything that extends that, I can get the attr_accessor's defined in the subclasses. Something like…
Lance
  • 75,200
  • 93
  • 289
  • 503
1 2
3
68 69