If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Enjoy an ad free experience by logging in. Not a member yet? Register.

What does Object as a class means?

Recently, I have come across a method with a parameter of "Object".

*Name of function*(Object obj){

//Code here//

}

What does Object in this case means and how can I manipulate it code-wise? I have read the official java manual and still have no idea what that exactly mean, so I would appreciate some insight regarding how this class can be used.

Object is the datatype. Object is the supertype of any object implicitly, so it will accept any object. Erasure when using generics with collections won't work quite the same way for which you would then use a type of extension to Object if you want to allow anything other an an absolute Object type, but that's out of scope for what you have here now.

Users who have thanked Fou-Lu for this post:

Object is the datatype. Object is the supertype of any object implicitly, so it will accept any object. Erasure when using generics with collections won't work quite the same way for which you would then use a type of extension to Object if you want to allow anything other an an absolute Object type, but that's out of scope for what you have here now.

No. An object is a complex type that is an instance. A String is an object (in Java, this isn't the case in every language). Primitives like int, char, double, boolean are not objects, although all do have wrappers Integer, Character, Double, Boolean which are objects. The idea is the same, in that these are datatypes, but differ in that primitives are not the same as objects.

A class (ie: Class<?>) is actually an object type, but not of the type defined. As in, String.class isn't an object of type String, its an object of type Class<String>. Sorry my previous statement wasn't quite clear on that; I meant that its not an instance of its defined type when referring to it as being an object.
The easiest way to think of it is simply as a datatype. The datatypes you have are primitive or complex, where complex are things like arrays and objects, and primitives are everything else. An object is simply an instance of a class constructed typically with the new keyword. The Object datatype is the implicit supertype of every complex datatype.
So the easiest thing to do is simply identify the primitives in Java: byte, short, int, long, float, double, boolean, and char. Every other datatype is an object (this does include enums and arrays in java).
Classes / templates shouldn't be considered as an object type; only instances of said template are an object type. Since a class itself cannot be used as a variable of its class type (if that makes any sense :/), it cannot possibly be defined as a type of object despite having implicit static methods: .class.
So I cannot do this:

PHP Code:

class T{ public static void main(String[] argv) {T o = T; }}

o cannot be assigned a datatype of T and be given an "object" that is in itself T (not an instance of T, but T in itself). Such behaviour really doesn't make any sense anyway. Typically, anything you'd do that would require an "instance" of a class (which isn't possible in the thought path we're on here since an instance of a class would be invoked with typically the new keyword), is used via reflection of the class type. That is, in java, you simply call ClassName.class and it gives you a Class<ClassName> back. You can operate on this to perform tasks like calling methods, changing visibility of methods and properties, and invoking new instances.

Class: the blueprint in which complex types are manufactured
Object: the result of construction off of the template defined by a class
primitive: explicit memory size and compiler knowledge of what to do with it. I can easily recast any primitive to anything I want. Nothing stops me from turning the char 'A' into the number 65 (since they are identical and a cast would show that). Character cannot be cast to an Integer though, since a Character is not a subclass of Integer.

PHP Code:

header('HTTP/1.1 420 Enhance Your Calm');

Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

Users who have thanked Fou-Lu for this post:

No. An object is a complex type that is an instance. A String is an object (in Java, this isn't the case in every language). Primitives like int, char, double, boolean are not objects, although all do have wrappers Integer, Character, Double, Boolean which are objects. The idea is the same, in that these are datatypes, but differ in that primitives are not the same as objects.

A class (ie: Class<?>) is actually an object type, but not of the type defined. As in, String.class isn't an object of type String, its an object of type Class<String>. Sorry my previous statement wasn't quite clear on that; I meant that its not an instance of its defined type when referring to it as being an object.
The easiest way to think of it is simply as a datatype. The datatypes you have are primitive or complex, where complex are things like arrays and objects, and primitives are everything else. An object is simply an instance of a class constructed typically with the new keyword. The Object datatype is the implicit supertype of every complex datatype.
So the easiest thing to do is simply identify the primitives in Java: byte, short, int, long, float, double, boolean, and char. Every other datatype is an object (this does include enums and arrays in java).
Classes / templates shouldn't be considered as an object type; only instances of said template are an object type. Since a class itself cannot be used as a variable of its class type (if that makes any sense :/), it cannot possibly be defined as a type of object despite having implicit static methods: .class.
So I cannot do this:

PHP Code:

class T
{
public static void main(String[] argv)
{
T o = T;
}
}

o cannot be assigned a datatype of T and be given an "object" that is in itself T (not an instance of T, but T in itself). Such behaviour really doesn't make any sense anyway. Typically, anything you'd do that would require an "instance" of a class (which isn't possible in the thought path we're on here since an instance of a class would be invoked with typically the new keyword), is used via reflection of the class type. That is, in java, you simply call ClassName.class and it gives you a Class<ClassName> back. You can operate on this to perform tasks like calling methods, changing visibility of methods and properties, and invoking new instances.

Class: the blueprint in which complex types are manufactured
Object: the result of construction off of the template defined by a class
primitive: explicit memory size and compiler knowledge of what to do with it. I can easily recast any primitive to anything I want. Nothing stops me from turning the char 'A' into the number 65 (since they are identical and a cast would show that). Character cannot be cast to an Integer though, since a Character is not a subclass of Integer.

In short, do you mean that every data types are from a class by itself. However, in this case Object, the only Classes we are only able to use are complex method(including array and enum) and not primitive ones. Am I right?

If that's the case, to manipulate say a string arraylist where it accepts an object, would it be something like this

The Object(in the API reference documentation) class sits at the top of the class hierarchy tree in the Java development environment. Every class in the Java system is a descendent (direct or indirect) of the Object class. The Object class defines the basic state and behavior that all objects must have, such as the ability to compare oneself to another object, to convert to a string, to wait on a condition variable, to notify other objects that a condition variable has changed, and to return the object's class.