Skip to content

Android EventHandler using Generics unsupported #860

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
NathanaelA opened this issue Oct 18, 2017 · 1 comment
Closed

Android EventHandler using Generics unsupported #860

NathanaelA opened this issue Oct 18, 2017 · 1 comment

Comments

@NathanaelA
Copy link
Contributor

Please, provide the details below:

Did you verify this is a real problem by searching

Yes

Tell us about the problem

If a interface using generics extend another interface the java building code is unable to be figured it out and you get the following build issues.

Please provide the following version numbers that your issue occurs with:

Current versions (3.2.x)

Did the error happen while the app was being constructed? (buildtime error)

tns build android

Please tell us how to recreate the issue in as much detail as possible.

Extend the Anyline.io energy module EventListener

TS code:

@Interfaces([at.nineyards.anyline.modules.energy.EnergyResultListener])
class ERListener extends java.lang.Object {
    private _owner: any;
    constructor(owner) {
        super();
        this._owner = new WeakRef(owner);
        return global.__native(this);
    }
    onResult(value: any): void {
        const owner: AnylineEnergy = this._owner.get();
        if (owner) {
            owner._onResult(value);
        }
    }
};

Error depending on which way you try to extend it:

D:\projects\nativescript\repos\nativescript-anyline\demo\platforms\android\src\main\java\com\tns\gen
\java\lang\Object_frnal_ts_helpers_l58_c38__ERListener.java:3: error: Object_frnal_ts_helpers_l58_c3
8__ERListener is not abstract and does not override abstract method onResult(EnergyResult) in Anylin
eModuleResultListener
public class Object_frnal_ts_helpers_l58_c38__ERListener extends java.lang.Object implements com.tns
.NativeScriptHashCodeProvider, at.nineyards.anyline.modules.energy.EnergyResultListener {
       ^
D:\projects\nativescript\repos\nativescript-anyline\demo\platforms\android\src\main\java\com\tns\gen
\java\lang\Object_frnal_ts_helpers_l58_c38__ERListener.java:9: error: name clash: onResult(AnylineSc
anResult) in Object_frnal_ts_helpers_l58_c38__ERListener and onResult(T) in AnylineModuleResultListe
ner have the same erasure, yet neither overrides the other
        public void onResult(at.nineyards.anyline.models.AnylineScanResult param_0)  {
                    ^
  where T is a type-variable:
    T extends AnylineScanResult declared in interface AnylineModuleResultListener
D:\projects\nativescript\repos\nativescript-anyline\demo\platforms\android\src\main\java\com\tns\gen
\at\nineyards\anyline\modules\energy\EnergyResultListener.java:3: error: EnergyResultListener is not
 abstract and does not override abstract method onResult(EnergyResult) in AnylineModuleResultListene
r
public class EnergyResultListener implements at.nineyards.anyline.modules.energy.EnergyResultListene
r {
       ^
D:\projects\nativescript\repos\nativescript-anyline\demo\platforms\android\src\main\java\com\tns\gen
\at\nineyards\anyline\modules\energy\EnergyResultListener.java:8: error: name clash: onResult(Anylin
eScanResult) in EnergyResultListener and onResult(T) in AnylineModuleResultListener have the same er
asure, yet neither overrides the other
        public void onResult(at.nineyards.anyline.models.AnylineScanResult param_0)  {
                    ^
  where T is a type-variable:
    T extends AnylineScanResult declared in interface AnylineModuleResultListener
D:\projects\nativescript\repos\nativescript-anyline\demo\platforms\android\src\main\java\com\tns\gen
\java\lang\Object_frnal_ts_helpers_l58_c38__ERListener.java:3: error: Object_frnal_ts_helpers_l58_c3
8__ERListener is not abstract and does not override abstract method onResult(EnergyResult) in Anylin
eModuleResultListener
public class Object_frnal_ts_helpers_l58_c38__ERListener extends java.lang.Object implements com.tns
.NativeScriptHashCodeProvider, at.nineyards.anyline.modules.energy.EnergyResultListener {
       ^
D:\projects\nativescript\repos\nativescript-anyline\demo\platforms\android\src\main\java\com\tns\gen
\java\lang\Object_frnal_ts_helpers_l58_c38__ERListener.java:9: error: name clash: onResult(AnylineSc
anResult) in Object_frnal_ts_helpers_l58_c38__ERListener and onResult(T) in AnylineModuleResultListe
ner have the same erasure, yet neither overrides the other
        public void onResult(at.nineyards.anyline.models.AnylineScanResult param_0)  {
                    ^
  where T is a type-variable:
    T extends AnylineScanResult declared in interface AnylineModuleResultListener

The only way past this issue was to create a Java class that extended that Listener, and have that listener call my own listener function that was not using generics. (All the code will be present in https://github.com/nathanael/nativescript-anyline)

@Plamen5kov
Copy link
Contributor

closing in favor of #689

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants