本文整理匯總了Java中java.lang.reflect.Modifier.isSynchronized方法的典型用法代碼示例。如果您正苦於以下問題:Java Modifier.isSynchronized方法的具體用法?Java Modifier.isSynchronized怎麽用?Java Modifier.isSynchronized使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.lang.reflect.Modifier
的用法示例。
在下文中一共展示了Modifier.isSynchronized方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getMethodFlags
import java.lang.reflect.Modifier; //導入方法依賴的package包/類
private static int getMethodFlags(Executable method) {
int flags = FunctionInfo.NONE;
int modifiers = method.getModifiers();
if (Modifier.isAbstract(modifiers)) {
flags |= FunctionInfo.ABSTRACT;
}
if (Modifier.isFinal(modifiers)) {
flags |= FunctionInfo.FINAL;
}
if (Modifier.isPublic(modifiers)) {
flags |= FunctionInfo.PUBLIC;
} else if (Modifier.isProtected(modifiers)) {
flags |= FunctionInfo.PROTECTED;
} else if (Modifier.isPrivate(modifiers)) {
flags |= FunctionInfo.PRIVATE;
} else {
flags |= FunctionInfo.DEFAULT;
}
if (Modifier.isStatic(modifiers)) {
flags |= FunctionInfo.STATIC;
}
if (Modifier.isSynchronized(modifiers)) {
flags |= FunctionInfo.SYNCHRONIZED;
}
return flags;
}
示例2: testClass
import java.lang.reflect.Modifier; //導入方法依賴的package包/類
/**
* Test all the public, unsynchronized methods of the given class. If
* isSelfTest is true, this is a self-test to ensure that the test program
* itself is working correctly. Should help ensure correctness of this
* program if it changes.
* <p/>
* @param aClass - the class to test
* @param isSelfTest - true if this is the special self-test class
* @throws SecurityException
*/
private static void testClass(Class<?> aClass, boolean isSelfTest) throws
Exception {
// Get all unsynchronized public methods via reflection. We don't need
// to test synchronized methods. By definition. they are already doing
// the right thing.
List<Method> methods = Arrays.asList(aClass.getDeclaredMethods());
for (Method m : methods) {
// skip synthetic methods, like default interface methods and lambdas
if (m.isSynthetic()) {
continue;
}
int modifiers = m.getModifiers();
if (Modifier.isPublic(modifiers)
&& !Modifier.isSynchronized(modifiers)) {
try {
testMethod(aClass, m);
} catch (TestFailedException e) {
if (isSelfTest) {
String methodName = e.getMethod().getName();
switch (methodName) {
case "should_pass":
throw new RuntimeException(
"Test failed: self-test failed. The 'should_pass' method did not pass the synchronization test. Check the test code.");
case "should_fail":
break;
default:
throw new RuntimeException(
"Test failed: something is amiss with the test. A TestFailedException was generated on a call to "
+ methodName + " which we didn't expect to test in the first place.");
}
} else {
throw new RuntimeException("Test failed: the method "
+ e.getMethod().toString()
+ " should be synchronized, but isn't.");
}
}
}
}
}
示例3: isAllModifiersContainSpecificModifier
import java.lang.reflect.Modifier; //導入方法依賴的package包/類
public static boolean isAllModifiersContainSpecificModifier(int allModifiers, int specificModifier) {
if (Modifier.isAbstract(allModifiers) && Modifier.isAbstract(specificModifier))
return true;
if (Modifier.isFinal(allModifiers) && Modifier.isFinal(specificModifier))
return true;
if (Modifier.isInterface(allModifiers) && Modifier.isInterface(specificModifier))
return true;
if (Modifier.isNative(allModifiers) && Modifier.isNative(specificModifier))
return true;
if (Modifier.isPrivate(allModifiers) && Modifier.isPrivate(specificModifier))
return true;
if (Modifier.isProtected(allModifiers) && Modifier.isProtected(specificModifier))
return true;
if (Modifier.isPublic(allModifiers) && Modifier.isPublic(specificModifier))
return true;
if (Modifier.isStatic(allModifiers) && Modifier.isStatic(specificModifier))
return true;
if (Modifier.isStrict(allModifiers) && Modifier.isStrict(specificModifier))
return true;
if (Modifier.isSynchronized(allModifiers) && Modifier.isSynchronized(specificModifier))
return true;
if (Modifier.isTransient(allModifiers) && Modifier.isTransient(specificModifier))
return true;
if (Modifier.isVolatile(allModifiers) && Modifier.isVolatile(specificModifier))
return true;
if (Modifier.isVolatile(allModifiers) && Modifier.isVolatile(specificModifier))
return true;
return false;
}
示例4: isSynchronized
import java.lang.reflect.Modifier; //導入方法依賴的package包/類
/** Returns true if the method is synchronized. */
public final boolean isSynchronized() {
return Modifier.isSynchronized(getModifiers());
}
示例5: isSynchronized
import java.lang.reflect.Modifier; //導入方法依賴的package包/類
/**
* Return true if this method is synchronized
*/
public boolean isSynchronized() {
return Modifier.isSynchronized(getModifiers());
}
示例6: isSynchronized
import java.lang.reflect.Modifier; //導入方法依賴的package包/類
/**
* @see Modifier#isSynchronized(int)
*/
default boolean isSynchronized() {
return Modifier.isSynchronized(getModifiers());
}
示例7: isSynchronized
import java.lang.reflect.Modifier; //導入方法依賴的package包/類
/**
* Tells whether the aspect member is synchronized or not;
*
* @return
*/
public final boolean isSynchronized() {
return Modifier.isSynchronized(getModifiers());
}