开发者

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

开发者 https://www.devze.com 2022-12-24 08:45 出处:网络
In this JDO, why is .class needed here? Query averageSalaryQu开发者_如何学编程ery = pm.newQuery(Employee.class);

In this JDO, why is .class needed here?

Query averageSalaryQu开发者_如何学编程ery = 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 ;)

0

精彩评论

暂无评论...
验证码 换一张
取 消