Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!npeer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!nx02.iad01.newshosting.com!newshosting.com!newspump.sol.net!news-out.readnews.com!transit3.readnews.com!news-out.news.tds.net!newsreading01.news.tds.net!53ab2750!not-for-mail From: "Donkey Hottie" Subject: Type of a generic class? Message-ID: <501D725E.56136.calajapr@time.synchro.net> X-Comment-To: All Newsgroups: comp.lang.java.programmer X-FTN-AREA: COMP.LANG.JAVA.PROGRAMMER X-FTN-MSGID: 1:261/38 bef2de9e Content-Type: text/plain; charset=IBM437 Content-Transfer-Encoding: 8bit X-Gateway: time.synchro.net [Synchronet 3.16a-Win32 NewsLink 1.98] Lines: 81 Date: Sat, 04 Aug 2012 19:43:54 GMT NNTP-Posting-Host: 69.21.70.65 X-Complaints-To: news@tds.net X-Trace: newsreading01.news.tds.net 1344109434 69.21.70.65 (Sat, 04 Aug 2012 14:43:54 CDT) NNTP-Posting-Date: Sat, 04 Aug 2012 14:43:54 CDT Organization: tds.net X-Received-Bytes: 3687 Xref: csiph.com comp.lang.java.programmer:17177 From: "Donkey Hottie" From: "Donkey Hottie" From: Donkey Hottie 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 ; } } -+- BBBS/Li6 v4.10 Dada-1 + Origin: Prism bbs (1:261/38) -+- Synchronet 3.16a-Win32 NewsLink 1.98 Time Warp of the Future BBS - telnet://time.synchro.net:24 -+- BBBS/Li6 v4.10 Dada-1 + Origin: Prism bbs (1:261/38) -+- Synchronet 3.16a-Win32 NewsLink 1.98 Time Warp of the Future BBS - telnet://time.synchro.net:24 --- BBBS/Li6 v4.10 Dada-1 * Origin: Prism bbs (1:261/38) --- Synchronet 3.16a-Win32 NewsLink 1.98 Time Warp of the Future BBS - telnet://time.synchro.net:24