【问题标题】:Which annotations may be applied at Loc1 in the code fragment代码片段中的 Loc1 可以应用哪些注解
【发布时间】:2021-04-07 02:39:05
【问题描述】:

我不知道正确答案是什么,请帮忙,请帮忙,请帮忙,请帮忙,请帮忙,请帮忙

@interface Resource {
    String name();
    int priority() default 0;
}

/* Loc1 */
class ProcessOrders {  }

Which two annotations may be applied at Loc1 in the code fragment? (Choose two.)
A. @Resource(priority=100)
    B. @Resource(priority=0)
    C. @Resource(name="Customer1", priority=100)
    D. @Resource(name="Customer1")
    E. @Resource

【问题讨论】:

    标签: java interface annotations


    【解决方案1】:

    看起来你现在正在通过考试或其他什么:)

    看,在 java 中,注解的参数可以具有默认值,例如 priority,或者在您的情况下定义为没有默认值(例如 name)。

    现在,如果您不定义默认值,这是一个强制参数,您必须指定它,否则如果您不指定任何内容,将使用默认值。

    如果您不定义强制参数,您的代码甚至无法编译。

    考虑到这一点,在你的答案中选择那些定义 name 和可选定义 priority) ;)

    【讨论】:

    • 那么,答案应该是C和D吧?所有建议的答案都显示 A 和 B,这让我感到困惑。
    猜你喜欢
    • 1970-01-01
    • 2011-11-24
    • 1970-01-01
    • 2013-08-08
    • 2014-01-23
    • 1970-01-01
    • 2019-03-18
    • 2010-11-30
    • 2011-07-17
    相关资源
    最近更新 更多