Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!border3.nntp.dca.giganews.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!news.giganews.com.POSTED!not-for-mail NNTP-Posting-Date: Thu, 02 Aug 2012 14:05:07 -0500 Date: Thu, 02 Aug 2012 22:04:26 +0300 From: Donkey Hottie User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:14.0) Gecko/20120714 Thunderbird/14.0 MIME-Version: 1.0 Newsgroups: comp.lang.java.programmer Subject: Type of a generic class? Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Message-ID: Lines: 64 X-Usenet-Provider: http://www.giganews.com X-Trace: sv3-NHBGD4S5dZjuXjOhZgf9IE20kSjplWdcA5yc4YgKeyC61fjcbuIcmCoEss0uzGNoD/ZrgbVoPk12C4d!zmQ+qnh3J4pgeIOOSG4YauMJyU/GOJJkqbHVPBW8gOXVEHxroILQ5/nux8JM4DSck9fvLA== X-Complaints-To: abuse@giganews.com X-DMCA-Notifications: http://www.giganews.com/info/dmca.html X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 3150 Xref: csiph.com comp.lang.java.programmer:16972 I have this class called Global. It is trying to be a simplistic simulation of global as in MUMPS/M language. It is a persistent variable, that is accessible everywhere, and retains it's value over time. I store them in a database. First problem I have is to translate the type to a lower level application API call. I can not leave the cast or type conversion to compiler only. For that I figured out that I may need a variable of Class, I'm using the variables isAssignableFrom(Class) to find out the correct API call. Could there be a simpler way? the final Class as a member variable. Is that really needed? How could I use some typeinfo (reflection API?) instead? If I could use serialization and store the objects that way maybe into BLOBs there would not be problems, but currently I can not do that. I would like to get rid of that "klass" argument for the Global. Any ideas? Class is a simple version containg only the important parts. public class Global { final String name ; final Connection conn ; final Class klass; public Global(String name, Connection conn, Class klass) { this.name = name ; this.conn = conn ; this.klass = klass; } @SuppressWarnings("unchecked") public T get() throws Exception { T rc = null; if (klass.isAssignableFrom(Boolean.class)) { rc = (T)SystemProperties.getSystemBoolean(name, conn); } else if(klass.isAssignableFrom(Date.class)) { rc = (T)SystemProperties.getSystemDate(name, conn); } else if (klass.isAssignableFrom(Long.class)) { rc = (T)SystemProperties.getSystemLong(name, conn); } else if (klass.isAssignableFrom(Integer.class)) { rc = (T)SystemProperties.getSystemInt(name, conn); } else if (klass.isAssignableFrom(String.class)) { rc = (T)SystemProperties.getSystemString(name, conn); } return rc ; } }