Working with the class keyword in Java

后端 未结 8 1314
梦毁少年i
梦毁少年i 2021-02-13 19:16

I don\'t really understand how the class keywords work in some instances.

For example, the get(ClientResponse.class) method takes the Cl

8条回答
  •  感情败类
    2021-02-13 19:35

    The very most important fact is - you don't need to have an instance to call the method. It's critically useful in situations when you cannot for some reason instantiate a class, e.g. it's abstract, or have only private constructor, or can only be correctly instantiated by some framework, like Spring or JSF.

    You can then call get to obtain an object of a requested type without even knowing where it does come from and how it get's created.

提交回复
热议问题