是否可以使用特殊字符声明java属性名称,例如:
private String var/name;
private int one+one;
我问这个问题是因为我需要从数据库中检索数据,其中一个列的名称是annoces/status
,并且我需要使用sql查询(不是hql或criteria)
最佳答案
这是不可能的:
Variable names are case-sensitive. A variable's name can be any legal identifier — an unlimited-length sequence of Unicode letters and digits, beginning with a letter, the dollar sign "$", or the underscore character "_". The convention, however, is to always begin your variable names with a letter, not "$" or "_". Additionally, the dollar sign character, by convention, is never used at all. You may find some situations where auto-generated names will contain the dollar sign, but your variable names should always avoid using it. A similar convention exists for the underscore character; while it's technically legal to begin your variable's name with "_", this practice is discouraged. White space is not permitted.
我不明白你为什么需要它。
编辑
您可以使用类似 bbr.sendQuery("Select Status, Name, Annonces/Sta AS annoncesSta, From table ",MyObject.class); 的内容使用AS,您可以更改结果中收到的列的名称。所以你在java类中的属性可以是“annoncesSta”。
无论如何,列名称都带有“/”,名称的最佳实践是:
- 公告Sta
- announces_sta
大多数映射器会自动处理这些名称。
关于java - java中如何在变量声明中使用特殊字符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13234550/