You can do that only if you know the type of the messages at compilation time. In that case, you can use the instantiate method of the class MessageInstance.