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-26



class Hoge<T>{
	private T var;
	public void setVar(T arg){var = arg;}
	public T getVar(){return var;}
}
//の様なクラスを
public class Test{
	public static void main(String[] args){
		Hoge<String> obj = new Hoge<String>();
	}
}
//の様にインスタンス化すると
class Hoge{
	private String var;
	public void setVar(String arg){var = arg;}
	public String getVar(){return var;}
}
//の様な内容で生成されるし
public class Test{
	public static void main(String[] args){
		Hoge<Integer> obj = new Hoge<Integer>();
	}
}
//の様にインスタンス化すると
class Hoge{
	private Integer var;
	public void setVar(Integer arg){var = arg;}
	public Integer getVar(){return var;}
}
//の様な内容で生成される。



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?