Tácio Mendes
Tácio Mendes

Reputation: 25

I wanna understand why this syntax works, and how

I've seen a very strange thing that i know it works, but i can't seem to understand exactly why and how this works.

i have a line of code that reads this:

_game._requestedState = new  (FlxU.getClass(FlxU.getClassName(_game._state,false)))();

Ok, so what i can see here, is, i'm invoking an annonymous constructor, by reflection. Is that it?

Thanks.

Upvotes: 2

Views: 57

Answers (1)

null
null

Reputation: 5255

There's no such thing as an anonymous constructor.

The method is called FlxU.getClassName, which makes it clear that there is in fact a name involved. It takes some _game._state, get's a class name from it and then gets the actual class from that name.

This is similar to getDefinitionByName(), which it likely uses internally.

Upvotes: 1

Related Questions