Java warning when calling DBusConnection.addSigHander in Java
binding
Tim Moloney
t.moloney at verizon.net
Thu Apr 27 05:21:05 PDT 2006
Matthew Johnson wrote:
> On Wed, 26 Apr 2006, Tim Moloney wrote:
>
>> Matthew Johnson wrote:
>>> On Tue, 25 Apr 2006, Tim Moloney wrote:
>>>
>>>> I get a couple of warnings when compiling the following line of
>>>> Java code inside Eclipse.
>>>>
>>>> this.connection.addSigHandler(Player.playingUriChanged.class, this);
>>>>
>>>> The warnings are:
>>>> - Type safety: The expression of type RhythmboxDbusProxy needs
>>>> unchecked conversion to conform to DBusSigHandler<T>
>>>> - Type safety: Unchecked invocation addSigHandler(Class,
>>>> DBusSigHandler) of the generic method addSigHandler(Class<T>,
>>>> DBusSigHandler<T>) of type DBusConnection
>>>>
>>
>> The orignal line was
>>
>> public class RhythmboxDbusProxy implements DBusSigHandler { ... }
>>
>> which I changed to
>>
>> public class RhythmboxDbusProxy implements
>> DBusSigHandler<Player.playingUriChanged> { ... }
>>
>> and that gets rid of the warning.
>>
>> However, I has to comment out the other three signals that
>> RhythmboxDbusProxy handles. If I used
>>
>> public class RhythmboxDbusProxy implements
>> DBusSigHandler<Player.playingChanged>,
>> DBusSignHandler<Player.playingUriChanged>,
>> DBusSigHandler<Player.elapsedChanged>,
>> DBusSigHandler<Shell.visibilityChanged> { ... }
>>
>> I get the following error messages.
>>
>> The interface DBusSigHandler cannot be implemented more than once
>> with different arguments:
>>
>> I understand this to mean that I have to create a separate class that
>> implements DBusSignal<signal> for each D-Bus signal that I want to
>> handle. That seems a bit much. I hope that I'm wrong.
>>
> Hmm. Generics isn't working exactly as I'd have hoped. I'd like people
> to be able to have the type safety there, this may mean living with the
> unchecked warning when they don't want it though.
>
> Even casting the signal to Class<? extends DBusSignal> doesn't help. The
> type parameterization of addSigHandler does stop you handling something
> with the wrong handler, so I don't really want to remove it, but if you
> use a generic handler you get this warning. I'm not really sure what to
> do about it.
>
> Matt
>
That's what I was afraid of. This appears to be a shortcoming of the
language that I'll just have to live with.
Thanks for the help. :)
Tim Moloney
More information about the dbus
mailing list