Last active
October 3, 2022 15:31
-
-
Save aman-junaid/b7b277ea6aeee054ed27b4a42c3a7073 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.aj.snippet.javamodule.a; | |
// default access modifier | |
class A { | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.aj.snippet.javamodule.a; | |
public class B { | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.aj.snippet.javamodule.b; | |
import java.lang.reflect.Field; | |
import java.lang.reflect.Method; | |
import com.aj.snippet.javamodule.a.A; | |
//This is not allowed as A has default access modifier and can be accessed within package | |
import com.aj.snippet.javamodule.a.B; | |
//This is allowed as B has public access modifier | |
public class Z { | |
void testMethod() { | |
try { | |
Class x = Class.forName("com.aj.snippet.javamodule.a.A"); | |
// But we can access the class A using reflection | |
Field[] fields = x.getFields(); | |
Method[] methods = x.getMethods(); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Demonstrating the issue with the non-modular approach of Java packaging.