From 94da2a0e3caf6ff5092d96c2048d97e854032dce Mon Sep 17 00:00:00 2001 From: tueem Date: Mon, 2 Dec 2024 21:20:49 +0100 Subject: [PATCH] change logic to always give objects the highest value --- .../java/net/tomatentum/marinara/util/ReflectionUtil.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/src/main/java/net/tomatentum/marinara/util/ReflectionUtil.java b/lib/src/main/java/net/tomatentum/marinara/util/ReflectionUtil.java index 4f80cff..2a65282 100644 --- a/lib/src/main/java/net/tomatentum/marinara/util/ReflectionUtil.java +++ b/lib/src/main/java/net/tomatentum/marinara/util/ReflectionUtil.java @@ -23,6 +23,10 @@ public final class ReflectionUtil { } public static int getCastDepth(Class child, Class parent) { + + if (parent.equals(Object.class)) + return Integer.MAX_VALUE; + if (!parent.isAssignableFrom(child)) { throw new IllegalArgumentException("The specified class is not a child class of the specified parent."); } @@ -77,7 +81,7 @@ public final class ReflectionUtil { Class currMostSpecific = null; for (Class currClass : classes) { int currCastDepth = getCastDepth(base, currClass); - if (currCastDepth < min) { + if (currCastDepth <= min) { min = currCastDepth; currMostSpecific = currClass; }