• 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
  • Liutauras Vilda
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Peter Rooke
  • Himai Minh
Bartenders:
  • Piet Souris
  • Mikalai Zaikin

RTTI - what does this mean

 
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

The intent of Java is that you use polymorphic method calls throughout your code, and use RTTI only when you must.

Thinking in Java, Third Edition. (Pg. 476)



What does this mean. Don't polymorphmic calls depend on RTTI? How can you make polymorphmic calls at runtime w/o knowing the exact type.

regards,
vijay.
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
I don't think Polymorphism calls depends RTTI.
Polymorphism and RTTI are different concepts.
What is polymorphism?
In object-oriented programming, polymorphism is the ability to process objects
differently denpending on their data type or class. For example, given a base class
shape, polymorphism enables the programmer to difine different area methods for any
number or derived classes, such as circles, rectangles , etc. No matter what shape an
object is, applying the area method to it will return the correct results.
In java, we get an object via reference. For example, Shape shape = new Circle();
shape get the reference to "new Circle", so the will know the exact type at runtime.
But I am not sure, so please let me know when you get the answer
 
Vijay Raj
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
At runtime, the exact type is known and we should thank RTTI for that. What I want to ask is, why are these two treated as separate concepts. Only because of RTTI is the use of polymorphic methods justified.

regards,
vijay.
 
author and iconoclast
Posts: 24204
44
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, not so much. What the passage means is that you should always prefer polymorphism to doing something like



There are all sorts of problems with this; the biggest one is that while polymorphism automatically handles the situation if a class C is added, this code would need to be changed. Another is that this code is much less efficient than using polymorphism.

So you see that in fact explicitly using RTTI is in some ways the exact opposite of polymorphism; it has none of the benefits, and many disadvantages.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
RTTI = Run Time Type Information
 
reply
    Bookmark Topic Watch Topic
  • New Topic