Jump to content

[Java] IPConnection addListener


Guest reto.koenig

Recommended Posts

Eine Kleine Frage zum Listener:

 

Die Implementation von addListener enthält exklusive oder (else if) Abfragen bzgl. des übergebenen Listeners...

 

So verhält sich der addListener aber 'falsch', wenn eine Instanz übergeben wird, welche mehrere Listender implementiert.

 

Besser wäre in diesem Fall also die Möglichkeit, sämtliche Listener in einem Aufwasch zu berücksichtigen:

 

boolean knownListener=false;

if(object instanceof EnumerateListener) {

  enumerateListener = (EnumerateListener)object;

  knownListener=true;

} if(object instanceof ConnectedListener) {

  connectedListener = (ConnectedListener)object;

  knownListener=true;

} if(object instanceof DisconnectedListener) {

  disconnectedListener = (DisconnectedListener)object;

  knownListener=true;

} if(!knownListener)

  throw new IllegalArgumentException("Unknown listener type");

}

 

?Oder ist euer Vorgehen gewollt?

 

Grüsse Reto

 

Link to comment
Share on other sites

  • 2 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...