From: Mateusz Warowny Date: Wed, 22 Mar 2023 11:50:47 +0000 (+0100) Subject: JAL-4152 Make return type of getInstance a generic type X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=e628e6b1dc30649da1c1a3b31d66ee19665c3c25;p=jalview.git JAL-4152 Make return type of getInstance a generic type --- diff --git a/src/jalview/bin/ApplicationSingletonProvider.java b/src/jalview/bin/ApplicationSingletonProvider.java index 450809a..1367fab 100644 --- a/src/jalview/bin/ApplicationSingletonProvider.java +++ b/src/jalview/bin/ApplicationSingletonProvider.java @@ -106,7 +106,8 @@ public class ApplicationSingletonProvider * @param c * @return */ - public static ApplicationSingletonI getInstance(Class c) + @SuppressWarnings("unchecked") + public static T getInstance(Class c) { Map, ApplicationSingletonI> map = getContextMap(); if (map.containsKey(c)) @@ -114,17 +115,16 @@ public class ApplicationSingletonProvider /* * singleton already created _or_ creation failed (null value stored) */ - return map.get(c); + return (T) map.get(c); } /* * create and save the singleton */ - ApplicationSingletonI o = map.get(c); + T o = null; try { - Constructor con = c - .getDeclaredConstructor(); + Constructor con = c.getDeclaredConstructor(); con.setAccessible(true); o = con.newInstance(); } catch (IllegalAccessException | InstantiationException