• Post Reply Bookmark Topic Watch Topic
  • New Topic

object ref assignment conversion  RSS feed

 
Soumy Kumar
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As per rules
"
An array can be converted to
1) class Object
2) to interface Cloneable or Serializable
3) to an array. only an array of object ref types can be converted to an array, and the old element type must be convertible to the new element type."

1) rule and
in 2) rule Cloneable is working ..not Serializable
For 3)rule Examples please


 
Carol Enderlin
drifter
Ranch Hand
Posts: 1364
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Next time you get a compile error and want help, post the compile error.

I tried compiling your code and when I un-commented the Serializable code I got cannot resolve symbol error. Serializiable is in the java.io package so you need to add an import (see code below).

C:\_Work\java>javac Fruits.java
Fruits.java:11: cannot resolve symbol
symbol : class Serializable
location: class Fruits
Serializable s=b; // compile error
^
1 error


 
Carol Enderlin
drifter
Ranch Hand
Posts: 1364
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure about your number 3.

Checked Java Language Specification and found this listed:

From any array type SC[] to any array type TC[], provided that SC and TC are reference types and there is a narrowing conversion from SC to TC.

I added to your code to assign arrays of bananas to variables for arrays of fruits and vice versa. Trying to understand which one requires a cast took at while since Fruits implements Bananas and not vice versa.

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!