Why “pm.newQuery(Employee.class)” and not “pm.newQuery(Employee)” in JDO?

StackOverflow https://stackoverflow.com/questions/2542215

  •  23-09-2019
  •  | 
  •  

문제

In this JDO, why is .class needed here?

Query averageSalaryQuery = pm.newQuery(Employee.class);

I would prefer to write this more concise syntax if possible?

Query averageSalaryQuery = pm.newQuery(Employee);
도움이 되었습니까?

해결책

Query averageSalaryQuery = pm.newQuery(Employee);

Well, it still has to be valid Java, which the above is not...

The way to refer to a class in Java is using the .class syntax.

다른 팁

Using the ".class" suffix is a convention of the language, so your second example is just semantically invalid. Nothing you can do about it really. It's equivalent to calling the getClass() method on an instantiation of the class, like:

Query averageSalaryQuery = pm.newQuery(new Employee().getClass())

So it's already a shortcut ;)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top