Created
August 7, 2019 15:08
-
-
Save edefazio/3f4f1c2bbde4db33d7698416e091f317 to your computer and use it in GitHub Desktop.
Using jdraft to dynamically build and create / use objects
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
import org.jdraft.*; | |
import org.jdraft.adhoc.*; | |
import org.jdraft.macro.*; | |
import java.net.UUID; | |
public class BuildAndUseTest extends TestCase { | |
public void testBuildAndUseModel(){ | |
_class _c = _class.of("demo.Point2D", new @_dto Object(){ | |
@_final int x, y; | |
public UUID uuid; | |
}); | |
System.out.println(_c); | |
_proxy _p1 = _proxy.of(_c, 2, 100); | |
_proxy _p2 = _p1.of(2, 100); | |
assertEquals( _p1, _p2); | |
assertEquals( _p1.instance, _p2.instance); //the underlying objects are == | |
assertEquals( _p1.hashCode(), _p2.hashCode()); //hashcodes are equal | |
//change p2 | |
_p2.set("uuid", UUID.randomUUID()); | |
assertFalse( _p1.equals( _p2)); //objects are not equal | |
assertFalse( _p1.hashCode() == _p2.hashCode()); //hashcodes are not equal | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The code built from :
is:
NOTES:
-Point2D() constructor accepting and setting all final non-initialized fields (x, y) ({@see @_autoConstructor})