Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - Java generic class instance
Java generic class instance
What the landlord wants is a custom generic class, and everything upstairs is jdk!

My code

Public class JavaBean & ltK>{

Private string userName =

Private string password = "";

private int age = 0;

Private K k = null

Public JavaBean(){

}

/**

* @ Return Age

*/

public int getAge() {

Regression age;

}

/**

* @param age Age to set

*/

Public invalid storage (integer) {

This.age = age;

}

/**

* @ Return password

*/

Public string getPassWord() {

Return password;

}

/**

* @param passWord Password to set.

*/

Public void setPassWord (

This.passWord = password;

}

/**

* @ returns the user name

*/

Public string getUserName() {

Returns the user name;

}

/**

* @param userName User name to set.

*/

Public void setUserName (

This.userName = user name;

}

Public K getString(){

Return k;

}

/**

* @param k k to set.

*/

public void setK(K k) {

this.k = k

}

}

-Testing

Public class TestMain {

Public static void main(String[] args) {

JavaBean & lt integer & gtbean2 = new JavaBean & lt integer & gt ();

bean 2 . setk(3);

JavaBean & lt string & gt bean1= newjavabean < String & gt ();

bean 1 . setk(" hello ");

}

}