Skip to content

Instantly share code, notes, and snippets.

@joaovarandas
Created August 4, 2016 13:43
Show Gist options
  • Save joaovarandas/51567bd3b576d48a4c574d60d5a60ba3 to your computer and use it in GitHub Desktop.
Save joaovarandas/51567bd3b576d48a4c574d60d5a60ba3 to your computer and use it in GitHub Desktop.
Equality Test for Nashorn-OpenJDK
var jts = [];
jts.push(java.lang.Boolean);
jts.push(java.lang.String);
jts.push(java.lang.Short);
jts.push(java.lang.Integer);
jts.push(java.lang.Long);
jts.push(java.lang.Double);
jts.push(Java.type("java.math.BigDecimal"));
var vs = [];
vs.push(10);
vs.push("10");
for(var j in vs) {
var n = vs[j];
print("Comparing a type '" + typeof n + "' source with value " + n);
for(var k in jts) {
var eq = new jts[k](n) == new jts[k](n);
var typeeq = new jts[k](n) === new jts[k](n);
var javaeq = (new jts[k](n)).equals(new jts[k](n));
print(jts[k].class.getName() + '[' + new jts[k](n) + ']');
print('\t == ' + eq);
print('\t === ' + typeeq);
print('\tequals ' + javaeq);
}
print("");
print("");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment