Skip to content

Commit

Permalink
Added example with opens directive
Browse files Browse the repository at this point in the history
  • Loading branch information
mydeveloperplanet committed Jan 7, 2018
1 parent 777898f commit 7de49ad
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.mydeveloperplanet.jpmshi.HiModules;

import java.lang.reflect.Method;

import static javax.xml.XMLConstants.XML_NS_PREFIX;

public class HelloModules {
Expand All @@ -11,6 +13,31 @@ public static void main(String[] args) {
System.out.println("The XML namespace prefix is: " + XML_NS_PREFIX);
HiModules hiModules = new HiModules();
System.out.println(hiModules.getHi());

checkExportsDirectiveWithReflection();
checkOpensDirectiveWithReflection();
}

private static void checkExportsDirectiveWithReflection() {
try {
Class c = Class.forName("com.mydeveloperplanet.jpmshi.HiModules");
Method m = c.getMethod("getHi");
System.out.println(m.invoke(c.getDeclaredConstructor().newInstance()));
}
catch (Throwable e) {
System.err.println(e);
}
}

private static void checkOpensDirectiveWithReflection() {
try {
Class c = Class.forName("com.mydeveloperplanet.jpmsopens.OpensModules");
Method m = c.getMethod("getHiOpens");
System.out.println(m.invoke(c.getDeclaredConstructor().newInstance()));
}
catch (Throwable e) {
System.err.println(e);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.mydeveloperplanet.jpmsopens;

/**
* Class in order to test the modules opens directive
*/
public class OpensModules {

public String getHiOpens() {
return "Hi Opens Directive!";
}

}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
module com.mydeveloperplanet.jpmshi {
exports com.mydeveloperplanet.jpmshi;
opens com.mydeveloperplanet.jpmsopens;
}

0 comments on commit 7de49ad

Please sign in to comment.