本文整理汇总了Java中java.security.BasicPermission.equals方法的典型用法代码示例。如果您正苦于以下问题:Java BasicPermission.equals方法的具体用法?Java BasicPermission.equals怎么用?Java BasicPermission.equals使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.security.BasicPermission
的用法示例。
在下文中一共展示了BasicPermission.equals方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import java.security.BasicPermission; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
BasicPermission bp1 = new BP("exitVM");
BasicPermission bp2 = new BP("exitVM.*");
StringBuffer sb = new StringBuffer();
// First, make sure the old restrictions on exitVM and exitVM.* still hold.
if (!bp1.implies(bp2)) sb.append("bp1 does not implies bp2\n");
if (!bp2.implies(bp1)) sb.append("bp2 does not implies bp1\n");
// Test against hashCode spec
if (bp1.hashCode() != bp1.getName().hashCode())
sb.append("bp1 hashCode not spec consistent\n");
if (bp2.hashCode() != bp2.getName().hashCode())
sb.append("bp2 hashCode not spec consistent\n");
// Test against equals spec
if (bp1.getName().equals(bp2.getName())) {
if (!bp1.equals(bp2)) {
sb.append("BP breaks equals spec\n");
}
}
if (!bp1.getName().equals(bp2.getName())) {
if (bp1.equals(bp2)) {
sb.append("BP breaks equals spec in another way\n");
}
}
// Tests against common knowledge: If equals, then hashCode should be same
if (bp1.equals(bp2)) {
if (bp1.hashCode() != bp2.hashCode()) {
sb.append("Equal objects have unequal hashCode?\n");
}
}
if (sb.length() > 0) {
throw new Exception(sb.toString());
}
}