0
votes

(1) my JMS producer has

class Fruit class Apple extends Fruit

(2) my JMS consumer has only

Class Fruit

(3) JMS consumer is listening on topic X, expecting to receive Fruit objects

(4) JMS producer sends an Apple object to topic X

Will the consumer be able to receive the Apple from the topic as a Fruit without falling over?

1
If you think just about polymorphic behaviour that could be fine, but your issue is more a classloading one. Because even if your source code is the same, it depends on which JVM classloader is your class loaded. In some cases the same class loaded in a different class loader gives you a ClassCastException.gersonZaragocin

1 Answers

0
votes

Short answer is no. The ObjectMessage sends a serialized Java object which means that you'd need to have the class in the Class path on the receiver side since you'd need the class definition to de-serialize the object and provide the implementation of the overridden methods in the subclass.

It's easy enough in this case to just ask your computer, write a simple set of sender and receivers and configure the class path to match your stated question and see what happens.