-
Notifications
You must be signed in to change notification settings - Fork 46
Introduce Class{Literal,Reference}Cast
Refaster rules
#1269
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
Conversation
Looks good. No mutations were possible for these changes. |
return s -> clazz.isInstance(s); | ||
} | ||
|
||
Function<Number, Integer> testClassLiteralCast() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curious why the pevious three tests threw exceptions as part of their signature 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like a copy-paste error; will drop!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think that this impacts type safety, and it matches the Error Prone Support code style.
Added a commit. Suggested commit message:
Introduce `Class{Literal,Reference}Cast` Refaster rules (#1269)
} | ||
} | ||
|
||
/** Prefer {@link Class#cast(Object)} method references over more verbose alternatives. */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Verbose" is perhaps a bit strong/unclear. I see that this mirrors the rules above, though. Will propose something.
return s -> clazz.isInstance(s); | ||
} | ||
|
||
Function<Number, Integer> testClassLiteralCast() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like a copy-paste error; will drop!
Class<? extends Integer> clazz = Integer.class; | ||
return i -> clazz.cast(i); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need the separate variable here. (It's used above to test for a non-matching scenario.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah! Makes sense 👍
Class(Reference|Literal)Cast
class rulesClass{Literal,Reference}Cast
Refaster rules
Looks good. No mutations were possible for these changes. |
543cf41
to
a073a27
Compare
Looks good. No mutations were possible for these changes. |
a073a27
to
553df03
Compare
|
Looks good. No mutations were possible for these changes. |
Class.class:cast
alternative more readable, especially when working with Streams.What are your guys thoughts?
Suggested commit message