Solved

java polymorphism EJB MDB

Posted on 2013-05-27
1
665 Views
Last Modified: 2013-06-01
Hi,

I was reading as

java is single dispatch language.
polymorphism works on method calls but not on method parameters


onMessage() of MDB takes Message as parameter where no compile time check happens.
onMessage() needs cast to Message to sub interface or impl to process message.


I am not clear on what above statements means.
Any links, sample code, resources, ideas highly appreciated. Thanks in advace
0
Comment
Question by:gudii9
1 Comment
 
LVL 19

Accepted Solution

by:
Jim Cakalic earned 500 total points
ID: 39202219
Here's an example from the Java EE Tutorial:
http://docs.oracle.com/javaee/6/tutorial/doc/bnbpo.html

The Message interface itself enumerates methods for accessing/modifying header properties and message acknowledgement. It is in each of its subinterfaces that the methods are defined for accessing/modifying the message body. So, for example, TextMessage defines the getText/setText methods.

You should know, from the design, what kind of message you are expecting (typically a TextMessage but could be something else). As per the tutorial link, you can interrogate the object you receive in onMessage using instanceof and then cast it to the correct subinterface to process the body or take an error handling path.

Regards,
Jim Cakalic
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now