How does a '.class' property work?

后端 未结 5 936
孤城傲影
孤城傲影 2020-12-06 09:54

First time developing in Java, and first time developing for Android, so it\'s quite a newbie question.

I currently have this code:

public void onBt         


        
5条回答
  •  忘掉有多难
    2020-12-06 10:11

    Class is a class that represents classes. :)

    It is not "Object". It is not a superclass or even in your "NewTourny" hierarchy. That is why you can't cast from a NewTourney to a Class.

    The .class property is an instance of Class that represents type information.

    You can use it to do reflective style calls to instantiate something you don't know the type of at compile time.

提交回复
热议问题