diff --git a/cscore/src/main/java/edu/wpi/first/cscore/VideoMode.java b/cscore/src/main/java/edu/wpi/first/cscore/VideoMode.java index 712f695bb6..b7478987c7 100644 --- a/cscore/src/main/java/edu/wpi/first/cscore/VideoMode.java +++ b/cscore/src/main/java/edu/wpi/first/cscore/VideoMode.java @@ -60,12 +60,9 @@ public class VideoMode { if (other == null) { return false; } - if (getClass() != other.getClass()) { - return false; - } - VideoMode mode = (VideoMode) other; - return pixelFormat == mode.pixelFormat + return other instanceof VideoMode mode + && pixelFormat == mode.pixelFormat && width == mode.width && height == mode.height && fps == mode.fps; diff --git a/cscore/src/main/java/edu/wpi/first/cscore/VideoSink.java b/cscore/src/main/java/edu/wpi/first/cscore/VideoSink.java index 1421aa9b99..bc755f321b 100644 --- a/cscore/src/main/java/edu/wpi/first/cscore/VideoSink.java +++ b/cscore/src/main/java/edu/wpi/first/cscore/VideoSink.java @@ -94,11 +94,7 @@ public class VideoSink implements AutoCloseable { if (other == null) { return false; } - if (getClass() != other.getClass()) { - return false; - } - VideoSink sink = (VideoSink) other; - return m_handle == sink.m_handle; + return other instanceof VideoSink sink && m_handle == sink.m_handle; } @Override diff --git a/cscore/src/main/java/edu/wpi/first/cscore/VideoSource.java b/cscore/src/main/java/edu/wpi/first/cscore/VideoSource.java index 89f82b6e87..36d3d5f7c8 100644 --- a/cscore/src/main/java/edu/wpi/first/cscore/VideoSource.java +++ b/cscore/src/main/java/edu/wpi/first/cscore/VideoSource.java @@ -131,11 +131,7 @@ public class VideoSource implements AutoCloseable { if (other == null) { return false; } - if (getClass() != other.getClass()) { - return false; - } - VideoSource source = (VideoSource) other; - return m_handle == source.m_handle; + return other instanceof VideoSource source && m_handle == source.m_handle; } @Override diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/util/Color.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/util/Color.java index 0653367ca9..8ab4c3498a 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/util/Color.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/util/Color.java @@ -117,12 +117,12 @@ public class Color { if (this == other) { return true; } - if (other == null || getClass() != other.getClass()) { + if (other == null) { return false; } - Color color = (Color) other; - return Double.compare(color.red, red) == 0 + return other instanceof Color color + && Double.compare(color.red, red) == 0 && Double.compare(color.green, green) == 0 && Double.compare(color.blue, blue) == 0; } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/util/Color8Bit.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/util/Color8Bit.java index 132ea64a41..f9983a5ae7 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/util/Color8Bit.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/util/Color8Bit.java @@ -69,12 +69,14 @@ public class Color8Bit { if (this == other) { return true; } - if (other == null || getClass() != other.getClass()) { + if (other == null) { return false; } - Color8Bit color8Bit = (Color8Bit) other; - return red == color8Bit.red && green == color8Bit.green && blue == color8Bit.blue; + return other instanceof Color8Bit color8Bit + && red == color8Bit.red + && green == color8Bit.green + && blue == color8Bit.blue; } @Override