zD12 / pircbotx

Automatically exported from code.google.com/p/pircbotx
0 stars 0 forks source link

Configuration.Builder and ListenerAdapter generics issue. #175

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Same issue as #133, but with ListenerAdapter instead of ListenerManager
=======================================================================

What steps will reproduce the problem?
1. Attempt to override PircBotX in another class
(public class CustomBot extends PircBotX)
2. Change my ListenerAdapter<PircBotX> class to ListenerAdapter<CustomBot>
(public class MessageListener extends ListenerAdapter<CustomBot>)
3. Attempt to pass in the new ListenerAdapter into a Configuration.Builder

What is the expected output? What do you see instead?
I expect the Configuration class to allow me to pass extensions of 
ListenerAdapter.
However, compile errors are generated as the ListenerAdapter is forced to be 
PircBotX without extension.

What version of the product are you using? On what operating system?
PircBotX 2.0.1 on Linux Mint 16

Please provide any additional information below.
This issue is very similar to #133 so I took the liberty to copy parts of the 
description, as my English isn't the best...

Thanks in advance!

Original issue reported on code.google.com by kinaj.e...@freenet.de on 1 May 2014 at 2:14

GoogleCodeExporter commented 9 years ago
Finally found a work-around:
Change your class to: public class MessageListener extends 
ListenerAdapter<CustomBot>
Change your method to: public void onMessage(MessageEvent<CustomBot> event)

Then, to avoid the addListener() error I described above, replace
builder.addListener(new MessageListener());
with
builder.getListenerManager().addListener(new MessageListener());

That seems to work. Good luck if you have the same problem.

Original comment by kinaj.e...@freenet.de on 6 May 2014 at 8:53

GoogleCodeExporter commented 9 years ago
Going through old issues, can you try the latest snapshot? This compiles for me

class CustomBot extends PircBotX {
    public CustomBot(Configuration<? extends PircBotX> configuration) {
        super(configuration);
    }
}

class MessageListener extends ListenerAdapter<CustomBot> {
    @Override
    public void onMessage(MessageEvent<CustomBot> event) throws Exception {
    }
}

public class IssueExample {
    public static void main(String[] args) {
        Configuration config = new Configuration.Builder()
                .addListener(new MessageListener())
                .buildConfiguration();
    }
}

Original comment by Lord.Qua...@gmail.com on 17 Jul 2014 at 1:12

GoogleCodeExporter commented 9 years ago
It looks like it's working now.
Thank you very much!

Original comment by kinaj.e...@freenet.de on 2 Oct 2014 at 8:22

GoogleCodeExporter commented 9 years ago
Great

Original comment by Lord.Qua...@gmail.com on 2 Oct 2014 at 9:22