public class Test01 {
public static void main(String[] args) {
//create generic type Gen instance and assign
//generic type of Gen is Integer
//it`s use of autoboxing to encapsulate
//the value 12 within an Integer Object
Gen g1 = new Gen();
g1.t = 12;
g1.getT();
//jdk1.7 enhancement type inference
Gen g2 = new Gen<>();
g2.t = "hello";
g2.getT();
//create generic type Gen instance and
//don`t assign generic type
Gen g3 = new Gen();
g3.t = new Date();
g3.getT();
}
}
//declared a generic type Gen
class Gen{
T t;
public void getT(){
System.out.println(t.getClass().getName());
}
}
class Gen{
T t;
public void getT(){
System.out.println(t.getClass().getName());
}
}
//declared a subclass for Gen
//subclass don`t define generic tyoes, allow the definition of declared
class SubGen1 extends Gen{}
//allows subclass to specify the superclass specific generic type
class SubGen2 extends Gen{}
//don`t allows superclass definition generic type
class SubGen3 extends Gen{}//compile-time error
//define generic interface
interface List extends Iterator{
void add(E e);
Iterator iterator();
}
//define generic interface
interface Iterator{
E next();
boolean hasNext();
}
//define subclass for interface
class MyList implements List {
@Override
public String next() {return null;}
@Override
public boolean hasNext() {return false;}
@Override
public void add(String e) {}
@Override
public Iterator iterator() {return null;}
//test generic interface
public static void main(String[] args) {
MyList ls = new MyList();
ls.add("hehe");//execute add method can only add Stirng type
}
}
结论:
1、定义泛型接口时,实现类如果声明时指定了泛型类型,那么后续调用时,在编译阶段只能使用该类型。
2、如果定义泛型接口时,实现类不指定接口的泛型类型,那么会报警告。
List is a raw type. References to generic type List should be parameterized。
说明当前泛型接口是一个 raw type.最好指定泛型是参数化的。
而且对于后续程序来讲这样也是不太可取的。
List l1 = new ArrayList<>();
List l2 = new ArrayList<>();
System.out.println(l1.getClass()==l2.getClass());
//Cannot perform instanceof check against parameterized type
//List. Use the form List> instead since further
//generic type information will be erased at runtime
System.out.println(l1 instanceof List);
public class Test {
public static void main(String[] args) {
new Gen(123);
new Gen("123");
new Gen(123.1);//compile-time error
Gen g = new Gen<>(123); //compile-time error
}
}
class Gen{
//define constructor use generic
public Gen(T t){
System.out.println(t);
}
}
public class Test05 {
public static void main(String[] args) {
Gen g1 = new Gen<>(123);
Gen g2 = new Gen(123);
Gen g3 = new Gen(123);
Gen g4 = new Gen<>(123);
}
}
class Gen{
//define constructor use generic
public Gen(T t){
System.out.println(t);
}
}
http://www.namhuy.net/475/how-to-install-gui-to-centos-minimal.html
I have centos 6.3 minimal running as web server. I’m looking to install gui to my server to vnc to my server. You can insta
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'option,changed_ids ) values('0ac91f167f754c8cbac00e9e3dc372
实例1:
package com.bijian.thread;
public class MyThread extends Thread {
private static ThreadLocal tl = new ThreadLocal() {
protected synchronized Object initialValue() {
return new Inte
var v = 'C9CFBAA3CAD0';
console.log(v);
var arr = v.split('');
for (var i = 0; i < arr.length; i ++) {
if (i % 2 == 0) arr[i] = '%' + arr[i];
}
console.log(arr.join(''));
console.log(v.r