Can You Access?

  • + 0 comments

    I came to the solution by adding the following lines to use Java reflection and access the private powerof2 method in Solution.Inner.Private:

    Solution.Inner inner = new Solution.Inner();
    Solution.Inner.Private innerPrivate = inner.new Private();
    o = innerPrivate;
    Method method = innerPrivate.getClass().getDeclaredMethod("powerof2", int.class);
    method.setAccessible(true); 
    String result = (String) method.invoke(o, num); 
    System.out.println(num + " is " + result);
    

    `