5黑马币
- package Test2;
- import java.io.FileNotFoundException;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.FileInputStream;
- import java.util.Collection;
- import java.util.Properties;
- public class demo5 {
- public static void main(String[] args) throws IOException, Exception, ReflectiveOperationException {
- InputStream ips = new FileInputStream("config.properties");
- Properties props = new Properties();
- props.load(ips);
- ips.close();
- String classforName = props.getProperty("className");
- Class clazz= Class.forName(classforName).getClass();
- Collection collection = (Collection) clazz.newInstance();
- person p = new person(2,3);
- person p2 = new person(3,4);
- person p3 = new person(1,3);
- person p4 = new person(1,3);
- person p5 = new person(2,3);
- collection.add(p);
- collection.add(p2);
- collection.add(p3);
- collection.add(p4);
- collection.add(p5);
- }
-
- }
- class person{
- int age;
- int Str;
- person(int a,int b){
- this.age = a;
- this.Str = b;
- }
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + Str;
- result = prime * result + age;
- return result;
- }
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- person other = (person) obj;
- if (Str != other.Str)
- return false;
- if (age != other.age)
- return false;
- return true;
- }
-
-
- }
复制代码
张孝详老师的Java高新技术反射:第27个视频:
这个类哪里有问题请高手指点一二:
这个类不知道怎么了我的电脑老是出现错误
|
-
图.jpg
(157.49 KB, 下载次数: 18)
这是软件运行时的异常
-
新.jpg
(132.62 KB, 下载次数: 11)
这个是软件需要的文件
|