java immutable系列_Java Immutable类代码示例
import com.jcabi.aspects.Immutable; //導入依賴的package包/類
/**
* This class is immutable?
* @param type The class to check
* @throws ImmutabilityChecker.Violation If it is mutable
*/
private void check(final Class> type)
throws ImmutabilityChecker.Violation {
synchronized (this.immutable) {
if (!this.ignore(type)) {
if (type.isInterface()
&& !type.isAnnotationPresent(Immutable.class)) {
throw new ImmutabilityChecker.Violation(
String.format(
"Interface '%s' is not annotated with @Immutable",
type.getName()
)
);
}
if (!type.isInterface()
&& !Modifier.isFinal(type.getModifiers())) {
throw new Violation(
String.format(
"Class '%s' is not final",
type.getName()
)
);
}
try {
this.fields(type);
} catch (final ImmutabilityChecker.Violation ex) {
throw new ImmutabilityChecker.Violation(
String.format("Class '%s' is mutable", type.getName()),
ex
);
}
this.immutable.add(type);
Logger.debug(this, "#check(%s): immutability checked", type);
}
}
}
總結
以上是生活随笔為你收集整理的java immutable系列_Java Immutable类代码示例的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 确定性有穷自动机(DFA算法) 非确定性
- 下一篇: java实现相同分数排名_java做成绩