0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

無名クラス(匿名クラス)によるインタフェース実装。

Last updated at Posted at 2016-07-27



interface Hoge{
	public abstract void method();
}
class Fuga implements Hoge{
	public void method(){
		System.out.println("method.");
	}
}
public class Test {
	public static void main(String[] args){
		Hoge hoge = new Fuga();
		hoge.method();
	}
}



//は、



interface Hoge{
	public abstract void method();
}
public class Test{
	public static void main(String[] args){
		//無名クラスによる実装を伴うならば
		//new インターフェース名() から始まる記述は可能。
		Hoge hoge = new Hoge(){
			public void method(){
				System.out.println("method.");
			}
		};
		//ここまでメソッドの実行は無し。
		hoge.method();
	}
}



//と等価(同じ挙動)。



0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?