java - 我可以在多行文本中换行 Java 方法名称吗?

标签 java spring-data-jpa

我知道您的第一 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/

相关文章:

JavaFX - 沿着平行于切线的路径进行动画处理

java - 错误 :Execution failed for task ':app:processDebugResources' . > java.io.IOException:无法在 android studio 中删除文件夹 ""

mysql - Spring Boot hibernate 错误: Error executing DDL via JDBC Statement with database name has bar symbol

database - 如何从 ElementCollection 中提取数据

java - 直接自引用导致循环(通过引用链: java. util.ArrayList[0]-

java - 通过URL导入图片并添加到面板时出错

java - Java 处理类型类参数的方式

java - java中无法获取正确的时区

java - Spring MVC 测试

java - 使用 Hibernate/JPA 实现 Java Server Faces 中的数据持久性