2

So basically, im implementing interface in a view, then pass the view as source of custom event, in one of 3 "instanceof" calls it return false.

View:

public class NamedOffensiveStatsView extends BagVectorPanel implements INamedOffensiveStatsView {

Event.toString():

@Override
public String toString() {
    StringBuilder sb = new StringBuilder();
    sb.append(this.getSource().getClass() + ": ");

e.toString() prints:

class pl.drag0nius.diablo3.DPSCalc.NamedOffensiveStats.NamedOffensiveStatsView$2

instanceof returning false:

@Override
public void eventFired(Event e) {
    logger.debug("eventFired: " + e.toString());
    if (e.getSource() instanceof INamedOffensiveStatsView) {

Also i cannot cast from view to it's interface.

Answer:

With help of my friend we found the issue.

The code calling event (inside initComponents() of view):

    jComboBox.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (comboBoxReady) {
                logger.debug("actionPerformed");
                listener.eventFired(new Event(this, "selection", jComboBox.getSelectedIndex()));
            }
        }
    });

What it should be:

    jComboBox.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (comboBoxReady) {
                logger.debug("actionPerformed");
                listener.eventFired(new Event(NamedOffensiveStatsView.this, "selection", jComboBox.getSelectedIndex()));
            }
        }
    });

"this" was referencing nested class, not the view.

3
  • Is e.getSource()==null where instanceof returns false? Commented Jun 30, 2012 at 15:52
  • 5
    I think you should put your edits as an answer and accepts your own answer. Commented Jun 30, 2012 at 15:56
  • the thing is i cant answer my own questions during first 10 hours after posting or something like that. Commented Jun 30, 2012 at 21:42

1 Answer 1

8

the $2 at the end of the classname indicates that the source seems to be an anonymous innerclass of NamedOffensiveStatsView. It therefore would not be an instance of NamedOffensiveStatsView

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.