dimanche 20 janvier 2019

Does Class.getCanonicalName have performance issue?

I'm developing a game engine based on LWJGL. And I need to develop an event system. Of course there are many kinds of events like KeyEvent or MouseButtonEvent and so on. Then the event processor should be able to tech the type of the event it get. I'm now plan to use event.getClass().getCanonicalName() to get the class name from the event variable, and then from a Hashmap get the exact processor for the event. But I do worried that it have some performance issue to use getCanonicalName rapidly. Should I make a member-variable to indicate what kind of event is it in the Event classes instead? Or, if there be some more elegant way to deal with things like this?

(By the way this is designed to have ability for users to add more Event type so we cannot make it too static.)





Aucun commentaire:

Enregistrer un commentaire