下边界
package com.test.generic;
import java.util.Collection;
public class TestGenericClass {
//泛型方法 ? extends E :泛型的限定
public static <E> void move(Collection<E> from,Collection<? super E> to)
{
for(E e:from)
{
to.add(e);
}
}
public static <K,V> void put(K key,V value)
{
}
}
通配符
package com.test.generic;
import java.awt.event.ItemEvent;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.eclipse.jdt.internal.compiler.ast.ThisReference;
import com.sun.org.apache.xerces.internal.util.NamespaceContextWrapper;
public class TestGeneric {
public static void main(String[] args)
{
// ? 通配符
Box<?> box2=new Box<String>("hello");
box2=new Box<Integer>(12);
}
}
文章来源地址https://www.toymoban.com/news/detail-624905.html
文章来源:https://www.toymoban.com/news/detail-624905.html
到了这里,关于javaee 泛型的上下边界和通配符的使用的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!