我有一个用户配置文件类,只是想知道加载它的最佳方式是什么。我有以下代码,想知道它是否是正确的方法。
UserProfile userProfile = null;
char[] password = {'a','b','c'};
for(UserProfile profile : UserProfiles){
if(compareUserNameAndPassword("userName", password)){
userProfile = profile;
}
}
我的个人资料课程:
package jlibfprint;
public class UserProfile extends Profile {
/**
* constructor
*/
public UserProfile(String userName, int id, char[] password){
this.name = userName;
this.id = id;
this.password = password;
}
/**
* Users password
*/
private char[] password;
/**
* Set User password
* @param password
*/
public void setPassword(char[] password){
this.password = password;
}
/**
* compare passwords
*/
public boolean compareUserNameAndPassword(String userName,char[] password) {
if(this.name.equals(userName) && this.password.equals(password)){
return true;
}
return false;
}
}