Isn't an array to int primitive?

B

byhesed

I know that primitive type variables cannot be converted to class
type, right?
But, how can the below code operate well?

   System.out.println(new int[10] instanceof Object);

The result is "true".

I am thinking that it is weird.
Isn't the anonymous array primitive type, is it?
Then, how can it be converted to class type, in this case, Object?

I think I know something incorrectly.
Please correct my wrong idea.
 
K

Knute Johnson

I know that primitive type variables cannot be converted to class
type, right?
But, how can the below code operate well?

   System.out.println(new int[10] instanceof Object);

The result is "true".

I am thinking that it is weird.
Isn't the anonymous array primitive type, is it?
No

Then, how can it be converted to class type, in this case, Object?

I think I know something incorrectly.
Please correct my wrong idea.

Arrays are Objects.
 
B

byhesed

I know that primitive type variables cannot be converted to class
type, right?
But, how can the below code operate well?

   System.out.println(new int[10] instanceof Object);

The result is "true".

I am thinking that it is weird.
Isn't the anonymous array primitive type, is it?
Then, how can it be converted to class type, in this case, Object?

I think I know something incorrectly.
Please correct my wrong idea.

Sorry. I've just solved my question.

The book says that "Arrays are objects."

Thank you.
 
B

byhesed

I know that primitive type variables cannot be converted to class
type, right?
But, how can the below code operate well?
   System.out.println(new int[10] instanceof Object);
The result is "true".
I am thinking that it is weird.
Isn't the anonymous array primitive type, is it?
No

Then, how can it be converted to class type, in this case, Object?
I think I know something incorrectly.
Please correct my wrong idea.

Arrays are Objects.

Wow, you fastly replied my question
Thank you :)
 
K

Knute Johnson

I know that primitive type variables cannot be converted to class
type, right?
But, how can the below code operate well?
   System.out.println(new int[10] instanceof Object);
The result is "true".
I am thinking that it is weird.
Isn't the anonymous array primitive type, is it?
No

Then, how can it be converted to class type, in this case, Object?
I think I know something incorrectly.
Please correct my wrong idea.

Arrays are Objects.

Wow, you fastly replied my question
Thank you :)

Timing, it's everything.
 
R

Roedy Green

I am thinking that it is weird.
Isn't the anonymous array primitive type, is it?
Then, how can it be converted to class type, in this case, Object?

Arrays are Objects. They are also built-in types with a few magic
properties other Objects do not have.

I suspect you are getting hung up on two different interpretations of
the meaning of the word "primitive".
--
Roedy Green Canadian Mind Products
http://mindprod.com
How long did it take after the car was invented before owners understood
cars would not work unless you regularly changed the oil and the tires?
We have gone 33 years and still it is rare to uncover a user who
understands computers don't work without regular backups.
 
L

Lew

byhesed said:
byhesed said:
I know that primitive type variables cannot be converted to class
type, right?
But, how can the below code operate well?

   System.out.println(new int[10] instanceof Object);

The result is "true".

I am thinking that it is weird.
Isn't the anonymous array primitive type, is it?
Then, how can it be converted to class type, in this case, Object?

I think I know something incorrectly.
Please correct my wrong idea.

Sorry. I've just solved my question.

The book says that "Arrays are objects."

What book? Please answer.

The authority is the Java Language Specification (JLS). Also, GIYF.
<http://java.sun.com/docs/books/jls/third_edition/html/arrays.html>

Not every tertiary author is as good as every other. Any author who
contradicts the JLS is plain wrong. Some authors explain the concepts very
well, many do not even when they technically are correct. The latter category
includes many bloggers, and the category of incorrect information includes
many, many more bloggers.

So trust the JLS and augment with a) the official Java tutorials, b) reputable
writers like Brian Goetz, and c) seminal books such as /Effective Java/, 2nd
ed., by Joshua Bloch (mandatory reading!).
<http://java.sun.com/docs/books/effective/>
 
L

Lawrence D'Oliveiro

Timing, it's everything.

“What’s the secret to telling a good joke?â€
“I don’t know, what’s the secret to t—â€
“Timing.â€
 
B

byhesed

byhesed said:
byhesed said:
I know that primitive type variables cannot be converted to class
type, right?
But, how can the below code operate well?
   System.out.println(new int[10] instanceof Object);
The result is "true".
I am thinking that it is weird.
Isn't the anonymous array primitive type, is it?
Then, how can it be converted to class type, in this case, Object?
I think I know something incorrectly.
Please correct my wrong idea.
Sorry. I've just solved my question.
The book says that "Arrays are objects."

What book?  Please answer.

The authority is the Java Language Specification (JLS).  Also, GIYF.
<http://java.sun.com/docs/books/jls/third_edition/html/arrays.html>

Not every tertiary author is as good as every other.  Any author who
contradicts the JLS is plain wrong.  Some authors explain the concepts very
well, many do not even when they technically are correct.  The latter category
includes many bloggers, and the category of incorrect information includes
many, many more bloggers.

So trust the JLS and augment with a) the official Java tutorials, b) reputable
writers like Brian Goetz, and c) seminal books such as /Effective Java/, 2nd
ed., by Joshua Bloch (mandatory reading!).
<http://java.sun.com/docs/books/effective/>

Sorry for late reply.

What I am reading is <Introduction to Java Programming brief verssion
8/e by Y. Daniel Liang>.

Thank you for your link(JLS), but isn't it too old?

I'll read Effective Java, thank you again.
 
L

Lew


Please don't quote sigs.
Sorry for late reply.

What I am reading is<Introduction to Java Programming brief verssion
8/e by Y. Daniel Liang>.

Thank you for your link(JLS), but isn't it too old?

No, it's current. The JLS is what *defines* the language. The other
references simply describe it. Thus, the JLS is the ultimate authority on
what is and is not legal in Java.
I'll read Effective Java, thank you again.

One hint for that book: he uses the terms "consider ("Consider static factory
methods instead of constructors") and "prefer" ("Prefer interfaces to abstract
classes") a lot. He means that. "Prefer" doesn't mean "always use".
"Consider" doesn't mean "only use". He's suggesting that we think about our
choices, not make them blindly.
 
B

byhesed

And it should only change when the language itself changes. The age of
the JLS says more about the degree of stability of Java than about the
usefulness of the JLS.

Patricia

Thank you!!! (especially Lew and Patricia)
I really appreciate your kindness.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,277
Latest member
VytoKetoReview

Latest Threads

Top