Write a public class method makeTestSet() which takes no argument, that creates and returns an empty unsorted set whose elements are declared to be of type EOHoverFrog.
public static int makeTestSet() {
Set<EOHoverFrog> set = new set<EOHoverFrog>();
}
Write a public class method makeTestList() which takes no arguments, that creates an returns an empty list whose elements are declared to be of type EOHoverFrog.
public static int makeTestList() {
Set<EOHoverFrog> list = new list<EOHoverFrog>();
}
Write a public class method makeTestSortedSet() which takes no argument, and creates and returns an empty sorted set whose elements are declared to be 开发者_如何学编程of type EOHoverFrog.
public static int makeTestSortedSet() {
Set<EOHoverFrog> set = new set<EOHoverFrog>();
}
Have I done this correctly?
This code contains errors that would be picked up by trying to compile the code with a Java compiler: the compiler will not accept these programs.
The compile errors should tell you a number of things are wrong with your answers.
Ill help you with one, and you can figure out the others
Write a public class method makeTestList() which takes no arguments, that creates an returns an empty list whose elements are declared to be of type EOHoverFrog.
public static int makeTestList() {
Set<EOHoverFrog> list = new list<EOHoverFrog>();
}
Ok, the directions say that you need a method with:
1) no arguments...
2) return an empty List with elements of type EOHoverFrog
Look at your code.
What type did you declare your makeTestList
method to return? int
. What's it supposed to return?
What is the declared type of what you are creating? Set
Whats it supposed to be?
What are you returning? I dont see a return statement.
The one statement in your method, what is it doing? Declaring a Set with the name list, and assigning a new list to it. Does that really make sense to you?
Keep in mind that Set
and List
are interfaces, and you can only create implementations. like Hashset
and ArrayList
.
As others have mentioned, this code probably wont even compile.
Answer to second task seems wrong (list is of type Set)
Same goes for answer to third task (you need an empty sortedSet)
精彩评论