Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Now using isAssignableFrom() to detect when a class implements a certain ... #653

Open
wants to merge 1 commit into from

1 participant

@jwcarman

...interface (Serializable and Externalizable).

James Carman Now uing isAssignableFrom() to detect when a class implements a certa…
…in interface (Serializable and Externalizable).
e1a663b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 2, 2014
  1. Now uing isAssignableFrom() to detect when a class implements a certa…

    James Carman authored
    …in interface (Serializable and Externalizable).
This page is out of date. Refresh to see the latest.
View
16 core/src/main/java/me/prettyprint/cassandra/serializers/SerializerTypeInferer.java
@@ -112,21 +112,7 @@ public static boolean isImplementedBy(Class<?> clazz, Class<?> target) {
if (null == clazz || null == target) {
return false;
}
-
- Class<?>[] interArr = clazz.getInterfaces();
- if (null == interArr) {
- return false;
- }
-
- for (Class<?> interfa : interArr) {
- if (interfa.equals(target)) {
- return true;
- }
- }
- if(clazz.getSuperclass()!=null) {
- return isImplementedBy(clazz.getSuperclass(), target);
- }
- return false;
+ return target.isAssignableFrom(clazz);
}
}
View
26 core/src/test/java/me/prettyprint/cassandra/serializers/SerializerTypeInfererTest.java
@@ -0,0 +1,26 @@
+package me.prettyprint.cassandra.serializers;
+
+import org.junit.Test;
+
+import java.io.Serializable;
+
+import static org.junit.Assert.*;
+
+/**
+ * Unit tests for the {@link me.prettyprint.cassandra.serializers.SerializerTypeInferer} class.
+ */
+public class SerializerTypeInfererTest {
+
+ @Test
+ public void testWhenImplementingInterfaceThatExtendsSerializable() {
+ assertTrue(SerializerTypeInferer.getSerializer(MyType.class) instanceof ObjectSerializer);
+ }
+
+ public static interface MySerializable extends Serializable {
+
+ }
+
+ public static class MyType implements MySerializable {
+
+ }
+}
Something went wrong with that request. Please try again.