why MyClass.class exists in java and MyField.field isn't?

后端 未结 4 552
南笙
南笙 2021-01-23 05:15

Let\'s say I have:

class A {
    Integer b;
    void c() {}
}

Why does Java have this syntax: A.class, and doesn\'t have a syntax

4条回答
  •  再見小時候
    2021-01-23 05:29

    I take it you want this info for logging and such. It is most unfortunate that such information is not available although the compiler has full access to such information.

    One with a little creativity you can get the information using reflection. I can't provide any examples for asthere are little requirements to follow and I'm not in the mood to completely waste my time :)

提交回复
热议问题