diff options
| author | Sven Eisenhauer <sven@sven-eisenhauer.net> | 2023-11-10 15:11:48 +0100 |
|---|---|---|
| committer | Sven Eisenhauer <sven@sven-eisenhauer.net> | 2023-11-10 15:11:48 +0100 |
| commit | 33613a85afc4b1481367fbe92a17ee59c240250b (patch) | |
| tree | 670b842326116b376b505ec2263878912fca97e2 /Master/Reference Architectures and Patterns/hjp5/examples/Listing4306.java | |
| download | Studium-master.tar.gz Studium-master.tar.bz2 | |
Diffstat (limited to 'Master/Reference Architectures and Patterns/hjp5/examples/Listing4306.java')
| -rw-r--r-- | Master/Reference Architectures and Patterns/hjp5/examples/Listing4306.java | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing4306.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing4306.java new file mode 100644 index 0000000..d4c6740 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing4306.java @@ -0,0 +1,56 @@ +/* Listing4306.java */
+
+import java.lang.reflect.*;
+
+public class Listing4306
+{
+ public static void main(String[] args)
+ {
+ Class clazz = TestConstructors.class;
+ //Formale Parameter definieren
+ Class[] formparas = new Class[2];
+ formparas[0] = String.class;
+ formparas[1] = String.class;
+ try {
+ Constructor cons = clazz.getConstructor(formparas);
+ //Aktuelle Argumente definieren
+ Object[] actargs = new Object[] {"eins", "zwei"};
+ Object obj = cons.newInstance(actargs);
+ ((TestConstructors)obj).print();
+ } catch (Exception e) {
+ System.err.println(e.toString());
+ System.exit(1);
+ }
+ }
+}
+
+class TestConstructors
+{
+ private String arg1;
+ private String arg2;
+
+ public TestConstructors()
+ {
+ arg1 = "leer";
+ arg2 = "leer";
+ }
+
+ public TestConstructors(String arg1)
+ {
+ this();
+ this.arg1 = arg1;
+ }
+
+ public TestConstructors(String arg1, String arg2)
+ {
+ this();
+ this.arg1 = arg1;
+ this.arg2 = arg2;
+ }
+
+ public void print()
+ {
+ System.out.println("arg1 = " + arg1);
+ System.out.println("arg2 = " + arg2);
+ }
+}
\ No newline at end of file |
