Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
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.

internalFindViewById raises "unchecked cast" warning #2090

Copy link
Copy link
@ened

Description

@ened
Issue body actions

Starting from recent appcompat library versions (I'm not sure which one exactly), the need to cast the result of findViewById seem to have gone away. In fact, if the casting in current form stays, then compiling with "-Xlint:unchecked" will raise warnings like this:

  required: T
  found:    View
  where T is a type-variable:
    T extends View declared in method <T>internalFindViewById(int)
/git/project/app/src/main/java/SomeActivity_.java:40: warning: [unchecked] unchecked cast
        return ((T) this.findViewById(id));

AndroidAnnotations version: 4.4.0
Android compile SDK version: 26

Annotated code:

@EActivity
public class SomeActivity extends AppCompatActivity {
}

Expected generated code:

@Override
public<T extends View> T internalFindViewById(int id) {
    return this.findViewById(id);
}

Actual generated code:

@Override
public<T extends View> T internalFindViewById(int id) {
    return ((T) this.findViewById(id));
}

This would probably require different style of code generation depending on the activities parent class (AppCompatActivity, Activity) and if the findViewById call supports the casting already.

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.