I have an assignment for class and the teacher has explicitly said No use of Java libraries, or any other libraries. (That precludes, for instance, the use of any Java Collections.) This means that NO IMPORT CLAUSES ARE ALLOWED.
I have used:
I didn't use any imports and from what I can see, is not apart of the Java Collections or Libraries. I just want to make sure otherwise I get a 0. Is it?
Rob Spoor wrote:Make sure you also don't use anything from java.lang. These don't need to be imported but are part of the core library. That means you can't use String, Object, Integer etc.
Hmmm. It depends what your tutor's 'rule' actually means. Is it "no import statements" or "no use of any libraries"?
Rob's quite right that java.lang is a library; but not allowing it means that you can't use any objects at all except arrays (because Object itself is also part of java.lang), which seems an odd way to learn an Object-Oriented language.
You might want to check with him/her to make sure exactly what the rule means.
Isn't it funny how there's always time and money enough to do it WRONG?
More seriously, I suspect it's a clumsy way of phrasing an exercise in using arrays and loops to stop people using collection classes that would make life too easy and side-step the things that are actually being tested.
Which raises an interesting point. Does xxx actually extend java.lang.Object or not? I suspect so since, as we all know, arrays are objects; but since it's part of the language it could simply be a structure dressed up to look like an Object.
I suspect it's stated in the JLS somewhere; I've just never had reason to find out.
Winston Gutkowski wrote:Does xxx actually extend java.lang.Object or not? I suspect so since, as we all know, arrays are objects; but since it's part of the language it could simply be a structure dressed up to look like an Object.
That's really a theoretical discussion for which I'm not sure if there's an answer, but it doesn't matter. If an int looks like an Object, behaves like an Object, has all the methods of class Object, then does it matter if it really extends Object or if the compiler just makes it look like an Object? What does the difference even mean if there's no practical difference when using arrays?
The JLS paragraph that Campbell linked to says that arrays inherit the members from Object, which seems to imply that arrays indeed extend Object.
Joined: Oct 13, 2005
…And if you scroll up, it says you can assign any array to an Object reference. If you scroll down there is an example where it prints the name of the superclass.
Jesper de Jong wrote:If an int looks like an Object, behaves like an Object, has all the methods of class Object, then does it matter if it really extends Object or if the compiler just makes it look like an Object?
Because of the rather ambiguous "rules" that started off this whole thread. It may be splitting hairs to you, but it might mean a 0 for poor Luke.
subject: Is an int array (int) apart of the Java Collections or Java Library?