Solved

java polymorphism EJB MDB

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

831 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