Skip to content
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

refactor: Remove unnecessary unchecked cast in getParent(Class) #3973

Merged

Conversation

slarse
Copy link
Collaborator

@slarse slarse commented Jun 3, 2021

Related to the discussion in #1846

I found a completely redundant unchecked cast in a method (getParent(Class)) where we actually have the runtime type to cast to! Using Class.cast() is safe, as it actually performs a cast at runtime.

It should be noted that in this method it doesn't actually matter, because the unchecked cast is preceded by a call to Class.isAssignableFrom(), which makes it "safe". But still, I think it's a nicer design to just avoid unchecked casts altogether when possible, because the not every Java developer is intimately familiar with what's safe and not when it comes to casting and type parameters.

@slarse slarse changed the title refactor: Remove unnecessary unchecked cast in getParent(Class) wip: refactor: Remove unnecessary unchecked cast in getParent(Class) Jun 3, 2021
@slarse slarse changed the title wip: refactor: Remove unnecessary unchecked cast in getParent(Class) review: refactor: Remove unnecessary unchecked cast in getParent(Class) Jun 3, 2021
@monperrus
Copy link
Collaborator

👍 will merge

@monperrus monperrus changed the title review: refactor: Remove unnecessary unchecked cast in getParent(Class) refactor: Remove unnecessary unchecked cast in getParent(Class) Jun 4, 2021
@monperrus monperrus merged commit e2f1353 into INRIA:master Jun 4, 2021
@slarse slarse deleted the issue/1846-remove-unnecessary-unchecked-cast branch June 4, 2021 08:21
@monperrus monperrus mentioned this pull request Aug 19, 2021
woutersmeenk pushed a commit to woutersmeenk/spoon that referenced this pull request Aug 29, 2021
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

Successfully merging this pull request may close these issues.

2 participants