【问题标题】:Name 'flight_Num' must match pattern '^[a-z][a-zA-Z0-9]*$'名称 'flight_Num' 必须匹配模式 '^[a-z][a-zA-Z0-9]*$'
【发布时间】:2012-10-22 08:35:54
【问题描述】:

当我在我的程序上运行 checkstyle 时,我不断收到此错误:

    NonRefundable.java:20:28: Name 'flight_Num' must match pattern '^[a-z][a-zA-Z0-9]*$'.

我不确定我需要做些什么来纠正这个问题。以下是针对此特定错误的 cmets:

/** Comments.
  *
  * @param flight_Num the flight number.
  * @param trip_Data the information stored in the Itinerary object.
  * @param base_Fare the double representing the initial cost of the trip.
  * @param fare_AdjustmentFactor the number factored into the baseFare and 
            discountFactor used to calculate totalFare.
  * @param discount_Factor the number factored into baseFare and 
  *         fare_AdjustmentFactor to calculate totalFare.
  */
  NonRefundable(String flight_Num, Itinerary trip_Data, double base_Fare,
            double fare_AdjustmentFactor, double discount_Factor) {

     super(flight_Num, trip_Data, base_Fare, fare_AdjustmentFactor);
     this.discountFactor = discount_Factor;
  }

【问题讨论】:

    标签: java javadoc checkstyle


    【解决方案1】:

    名称 'flight_Num' 必须匹配模式 '^[a-z][a-zA-Z0-9]*$'

    表示flight_Num中的_字符是不允许的。

    【讨论】:

    • 如果不允许,你将如何重命名这个变量?
    • @IgorGanapolsky 你是如何用上述错误重命名常量的?即使我也面临同样的错误
    【解决方案2】:

    您可能想查看 checkstyle 文档,我希望您在解决第一个问题时会看到这一点,但请从参数名称中删除下划线。

    NonRefundable(String flightNum, Itinerary tripData, double baseFare,
            double fareAdjustmentFactor, double discountFactor)
    

    http://checkstyle.sourceforge.net/config_naming.html

    您可以查看各种样式指南,参数名称往往是驼峰式的,如本文所示。

    http://www.cwu.edu/~gellenbe/javastyle/parameter.html

    【讨论】:

      【解决方案3】:

      Since Checkstyle 3.0

      如果无法删除下划线,可以通过以下方式抑制:

      // SUPPRESS CHECKSTYLE ParameterName
      NonRefundable(...)
      

      Related question

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-02-11
        • 2010-12-11
        • 2019-05-31
        • 2015-01-07
        • 2021-11-09
        • 1970-01-01
        • 1970-01-01
        • 2011-11-09
        相关资源
        最近更新 更多