#:(

6 messages · Page 1 of 1 (latest)

mossy breachBOT
#

This post has been reserved for your question.

Hey @tough dust! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

drifting root
#

..... What?

drifting root
#

I mean, Java supports something called "reflection." Among other things it's possible, when you have a given object at runtime, to ask it what's its class. (Just call getClass() on it.) Rather than being limited to being allowed what the compiler knows is allowed because of the variable types.

You can do tons of things with reflection, obvious examples being list the available fields, methods and constructiors in the class.
Not going into details, for all this to be possible, you need the class to be represented as an object you can query stuff on.
So basically, any class available in the program, can also be accessed as a Class object.

Example:

Class<String> stringClass = String.class;
// or
Class<?> otherStringClass = "Hello".getClass();
craggy viper
#

What a strange question. Can you be a bit more specific when you say "can classes behave as an object"? Behave how? Can you give an example (preferably as a code snippet)