2009-01-09 14:13:17 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* Copyright (c) 2002 - 2008 IBM Corporation.
|
|
|
|
* All rights reserved. This program and the accompanying materials
|
|
|
|
* are made available under the terms of the Eclipse Public License v1.0
|
|
|
|
* which accompanies this distribution, and is available at
|
|
|
|
* http://www.eclipse.org/legal/epl-v10.html
|
|
|
|
*
|
|
|
|
* Contributors:
|
|
|
|
* IBM Corporation - initial API and implementation
|
|
|
|
*****************************************************************************/
|
2008-12-16 15:14:00 +00:00
|
|
|
public class AnonymousClass {
|
|
|
|
private interface Foo {
|
|
|
|
public int getValue();
|
|
|
|
public int getValueBase();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void main(String[] args) {
|
2018-06-04 18:16:36 +00:00
|
|
|
final Integer base = Integer.valueOf(6);
|
2008-12-16 15:14:00 +00:00
|
|
|
|
|
|
|
Foo f= new Foo() {
|
|
|
|
int value = 3;
|
2013-06-25 15:57:37 +00:00
|
|
|
|
2017-06-27 15:42:05 +00:00
|
|
|
@Override
|
2013-06-25 15:57:37 +00:00
|
|
|
public int getValue() { return value; }
|
|
|
|
|
2017-06-27 15:42:05 +00:00
|
|
|
@Override
|
2013-06-25 15:57:37 +00:00
|
|
|
public int getValueBase() { return value - base.intValue(); }
|
2008-12-16 15:14:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
System.out.println(f.getValue());
|
|
|
|
System.out.println(f.getValueBase());
|
|
|
|
|
|
|
|
(new AnonymousClass()).method();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void method() {
|
2018-06-04 18:16:36 +00:00
|
|
|
final Integer base = Integer.valueOf(7);
|
2008-12-16 15:14:00 +00:00
|
|
|
|
|
|
|
abstract class FooImpl implements Foo {
|
|
|
|
int y;
|
|
|
|
|
2013-06-25 15:57:37 +00:00
|
|
|
|
2017-06-27 15:42:05 +00:00
|
|
|
@Override
|
2013-06-25 15:57:37 +00:00
|
|
|
public abstract int getValue();
|
2008-12-16 15:14:00 +00:00
|
|
|
|
|
|
|
FooImpl(int _y) {
|
|
|
|
y = _y;
|
|
|
|
}
|
|
|
|
|
2013-06-25 15:57:37 +00:00
|
|
|
|
2017-06-27 15:42:05 +00:00
|
|
|
@Override
|
2013-06-25 15:57:37 +00:00
|
|
|
public int getValueBase() {
|
2008-12-16 15:14:00 +00:00
|
|
|
return y + getValue() - base.intValue();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Foo f= new FooImpl(-4) {
|
2013-06-25 15:57:37 +00:00
|
|
|
|
2017-06-27 15:42:05 +00:00
|
|
|
@Override
|
2013-06-25 15:57:37 +00:00
|
|
|
public int getValue() { return 7; }
|
2008-12-16 15:14:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
System.out.println(f.getValue());
|
|
|
|
System.out.println(f.getValueBase());
|
|
|
|
}
|
|
|
|
}
|