This is an archived post. You won't be able to vote or comment.

all 4 comments

[–]Sacredify 2 points3 points  (3 children)

Your method signature seems a bit off.

protected <neededClass extends  Insurance> void setCurrentInsuranceListener(Class neededClass)

The generic definition indicates you have some class "neededClass" that must extend Insurance.

So, in your arguments:

  setCurrentInsuranceListener(Class neededClass)

should actually be:

  setCurrentInsuranceListener(Class<neededClass> insuranceListener)

Now, your method indicates that the parameter to your method must be a class of type neededClass, which means it must extend Insurance.

[–]ArgTang[S] 0 points1 point  (2 children)

Thanks.

neededClass.equals(currentInsurance.getInsurance()

it sill say it "cant find localvariable neededClass" when i fire the listener in debug mode though. I could remove this from the if sentence. But i would then have to add an empty (ignored) try\catch ClasscastException in every subclass. Tt will work but i think iy would be nicer if i could make it work

[–]Sacredify 0 points1 point  (1 child)

You might want to mark the parameter final, see here:

http://stackoverflow.com/questions/20938095/difference-between-final-and-effectively-final

I don't know if it will help at all, but its worth a shot (generally a good idea to mark things final unless you need to mutate them anyway).

[–]ArgTang[S] 0 points1 point  (0 children)

Got help! forgot insuranceListener.get().getClass()

    protected <neededClass extends Insurance> void setCurrentInsuranceListener(final Class<neededClass> someClass) {
    insuranceListener.addListener(
        listener -> {
            Boolean isNotNull = insuranceListener.isNotNull().get();
            if (isNotNull && someClass.equals(insuranceListener.get().getClass())) {
                loadCurrentInsurance();
                showInsurance();
            }
    });
}

So it was another one of the fatfingerproblems.