Skip to content
This repository was archived by the owner on Feb 26, 2023. It is now read-only.
This repository was archived by the owner on Feb 26, 2023. It is now read-only.

@Extra on primitives doesn't compile with javac #92

@pyricau

Description

@pyricau

Given the following code :

@EActivity
public class ExtraInjectedActivity extends Activity {

    @Extra("intExtra")
    int intExtra;

}

The interesting part of the generated code is :

public final class ExtraInjectedActivity_
    extends ExtraInjectedActivity
{
    // ...

    private void init_(Bundle savedInstanceState) {
        Bundle extras_ = this.getIntent().getExtras();
        if (extras_!= null) {
            if (extras_.containsKey("intExtra")) {
                try {
                    intExtra = cast_(extras_.get("intExtra"));
                } catch (ClassCastException e) {
                    Log.e("ExtraInjectedActivity_", "Could not cast extra to expected type, the field is left to its default value", e);
                }
            }
        }
    }

    @SuppressWarnings("unchecked")
    private<T >T cast_(Object object) {
        return ((T) object);
    }

}

It compiles well with Eclipse compiler.

It does not compile with javac compiler, giving the following error :

type parameters of <T>T cannot be determined; no unique maximal instance exists for type variable T with upper bounds int,java.lang.Object

The problematic line is:

intExtra = cast_(extras_.get("intExtra"));

The problem is kind of related to the one described here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions