• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

object ref assignment conversion

 
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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


 
drifter
Posts: 1364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 1364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Fire me boy! Cool, soothing, shameless self promotion:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic