我知道您的第一 react 是“您到底为什么要这样做,您的方法名称显然很荒谬”,但这是因为我使用的是 Spring Boot JPA,您可以在其中使用方法名称为您构造查询反射(reflection)(这太棒了)。但是,当基于几个不同的列进行查询并且实体变量的名称较长时,方法名称最终变得非常长且难以阅读,所以我想知道是否有一种方法可以将它拆分成多行?
目前我有类似的东西(针对这个问题进行了简化):
public List<Employee> findByFirstNameAndLastNameAndAgeBetweenAndBirthdayBefore(String firstName, String lastName, Integer minAge, Integer maxAge, Date maxBirthday);
我希望我的代码更像:
public List<Employee> findBy
FirstName
AndLastName
AndAgeBetween
AndBirthdayBefore
(String firstName, String lastName, Integer minAge, Integer maxAge, Date maxBirthday);
这有可能吗?
最佳答案
A method name是一个 identifier , 由 IdentifierChars
组成.
IdentifierChars
定义为以 Java Letter 开头,之后可能是 Java Letter 或 Digit。这些在 Character.isJavaIdentifierPart
的 Javadoc 中有描述。 (和 isJavaIdentifierStart
):
A character may be part of a Java identifier if any of the following are true:
- it is a letter it is a currency symbol (such as '$') it is a
- connecting punctuation character (such as '_')
- it is a digit
- it is a numeric letter (such as a Roman numeral character)
- it is a combining mark
- it is a non-spacing mark
isIdentifierIgnorable(codePoint)
returns true
和isIdentifierIgnorable(int)
说(强调我的):
The following Unicode characters are ignorable in a Java identifier or a Unicode identifier:
- ISO control characters that are not whitespace
- '\u0000' through '\u0008'
- '\u000E' through '\u001B'
- '\u007F' through '\u009F'
- all characters that have the FORMAT general category value
所以不可以,方法名称中不能有换行符。
关于java - 我可以在多行文本中换行 Java 方法名称吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48992618/