欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

这个类里有多少错误?

程序员文章站 2022-07-14 19:04:30
...
Java基础:

下面的类里有几处错误? 不通过工具,你能很快的找出来吗?试一下吧!


import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.junit.Test;


public class Test {

	static class Person {
		public void m(Collection<Person> persons) {
			
		}
	}
	
	static class Employee extends Person {
		public void <T> test() {
		}
		
	}
	
	static class Student extends Person {
		public void m2(Collection<Student> students) {
			super.m(students);
		}
		
	}
	

	public void arrayStoreExceptionTest() {
		Person[] persons = new Employee[5];
		persons[0] = new Employee();
		persons[1] = new Student();
	}
	
	
	@Test
	public void arrayStoreTest() {
		Person[] persons = new Person[2];
		persons[0] = new Employee();
		persons[1] = new Student();
	}
	
	public void genericTest() {
		List<Person> personList = new ArrayList<Employee>();
		
	}
	
	
	
	
	
	static class Generic<T> {
		
		static T t;
		
		static void method1(T t) {
			
		}
		void m1(T t){
			
		}
		
	}
}



相关标签: java