Comparable w[] = new Comparable[5];
w[0] = 1;
w[1] = "string";
w[2] = 2.0;
Is it a good way? And actually why does it work (I tried it just randomly)? Maybe because Comparable extends Integers, Strings, Doubles etc.? So what?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you can’t think of a good reason to do some thing, its probably not a good idea. 😉
Numbers and Strings implement Comparable, but you have the right idea.
There are many odd things you can do in Java, but most of them don’t have a use. 😉
In this case, its not particularly useful because the objects are not Comparable with each other. e.g. Arrays.sort(w); won’t work.