Solved

java polymorphism EJB MDB

Posted on 2013-05-27
1
667 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

932 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

9 Experts available now in Live!

Get 1:1 Help Now