Contents
See also
Powered by
|
Example for the JavaParty Object Model
- Source code
-
/* ***************************************************************************
* JavaParty
*
* Copyright (C) 1996-2002 The JavaParty Team, University of Karlsruhe
*
* Permission is hereby granted to modify and use this software for research
* and teaching purposes. Modification for commercial purposes requires
* prior written permission by the author.
*
* The software, or modifications thereof, may be redistributed only
* if this copyright notice stays attached.
*****************************************************************************/
/*
* $Revision: 3190 $
* $Date: 2007-03-27 21:49:37 +0200 (Tue, 27 Mar 2007) $
*/
package examples;
/** Instances of this class are used to test parameter passing */
class Param implements java.io.Serializable {}
/**
* @author Bernhard Haumacher
*/
public remote class ObjectModel {
Param p;
public void foo(Param p) {
this.p = p;
}
static Param q;
public static void bar(Param q) {
ObjectModel.q = q;
}
public void test() {
Param a = new Param();
// invoke method of same object without a reference
foo(a);
if (this.p != a) throw new RuntimeException("(a)");
// invoke method of same object with this reference
this.foo(a);
if (this.p != a) throw new RuntimeException("(b)");
ObjectModel model = this;
// invoke method of same object with arbitrary reference
model.foo(a);
if (this.p == a) throw new RuntimeException("(c)");
// invoke static method from instance method
bar(a);
if (ObjectModel.q == a) throw new RuntimeException("(d)");
// invoke static method from instance method with class name
// reference
ObjectModel.bar(a);
if (ObjectModel.q == a) throw new RuntimeException("(e)");
}
public static void testStatic() {
Param a = new Param();
// invoke static method of same class
bar(a);
if (ObjectModel.q != a) throw new RuntimeException("(f)");
// invoke static method of same class with class name
// reference
// TBD: This does not work correctly and throws an exception
// (see BUG/0061).
// ObjectModel.bar(a);
// if (ObjectModel.q != a) throw new RuntimeException("(g)");
}
public static void main(String args[]) {
new ObjectModel().test();
testStatic();
System.out.println("Test completed successfully.");
}
}
|