Hello, can you please help me with this ? I'm not sure I understand the logic behind the task.
package com.codegym.task.task21.task2102;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
/*
Compare modifiers
*/
public class Solution {
public static void main(String[] args) {
int classModifiers = Solution.class.getModifiers();
System.out.println(isModifierSet(classModifiers, Modifier.PUBLIC)); //true
System.out.println(isModifierSet(classModifiers, Modifier.STATIC)); //false
int methodModifiers = getMainMethod().getModifiers();
System.out.println(isModifierSet(methodModifiers, Modifier.STATIC)); //true
}
public static boolean isModifierSet(int allModifiers, int specificModifier) {
if(Integer.toBinaryString(specificModifier).equals(Integer.toBinaryString(allModifiers)))
return true;
else
return false;
}
private static Method getMainMethod() {
Method[] methods = Solution.class.getDeclaredMethods();
for (Method method : methods) {
if (method.getName().equalsIgnoreCase("main")) return method;
}
return null;
}
}