Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #17114

Re: Type of a generic class?

Path csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!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 Sat, 04 Aug 2012 05:47:07 -0500
Date Sat, 04 Aug 2012 13:46:45 +0300
From Donkey Hottie <donkey@fredriksson.dy.fi>
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 Re: Type of a generic class?
References <qivqe9-k9.ln1@whirlwind.fredriksson.dy.fi>
In-Reply-To <qivqe9-k9.ln1@whirlwind.fredriksson.dy.fi>
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding 7bit
Message-ID <l5bve9-s1b.ln1@whirlwind.fredriksson.dy.fi> (permalink)
Lines 105
X-Usenet-Provider http://www.giganews.com
X-Trace sv3-2G1otBmvAtBlHImxy3FuCUlJzo48EEHjlEmjC6eFXjjmVxXmyDObztUIFOfh72eEzAheR+rptK9QWFc!IjVw+0H1qAUbNJdm+Frl7q1gxXw/YHdr9rdp1zseUW+4FGeb9KW4geZi4GVCIxmIiU1hac4=
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 4530
Xref csiph.com comp.lang.java.programmer:17114

Show key headers only | View raw


02.08.2012 22:04, Donkey Hottie kirjoitti:
> 
> 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.

Actually I renamed this to a SystemProperty, and will implement the
Global<T extends java.io.Serializable> later. It will act just like
MUMPS Global and does not need any clutterin oddities. Any serializable
objects just serialized to a BLOB.

I have a separate use case for that too.

public class Global<T extends java.io.Serializable>
{

    private static final Log LOG = LogFactoryUtil.getLog(Global.class);
    final String name;
    final Connection conn;

    public Global(String name, Connection conn)
    {
        this.name = name;
        this.conn = conn;
    }

    public T get() throws Exception
    {
        T rc = null;
        LOG.info(String.format("Returning Global value %s=%s ",
                this.name, String.valueOf(rc)));
        throw new Exception("Not yet implemented!");
    }

    public void set(T value) throws Exception
    {
        LOG.info(String.format("Setting Global value %s=%s ",
                this.name, String.valueOf(value)));
        throw new Exception("Not yet implemented!");
    }
}


> 
> 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<T>, I'm using
> the variables isAssignableFrom(Class) to find out the correct API call.
> Could there be a simpler way?
> 
> the final Class<T> 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<T>. Any
> ideas?
> 
> Class is a simple version containg only the important parts.
> 
> public class Global<T extends Object>
> {
>     final String name ;
>     final Connection conn ;
>     final Class<T> klass;
>     public Global(String name, Connection conn, Class<T> 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 ;
>     }
> }
> 

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

Type of a generic class? Donkey Hottie <donkey@fredriksson.dy.fi> - 2012-08-02 22:04 +0300
  Re: Type of a generic class? Lew <lewbloch@gmail.com> - 2012-08-02 14:01 -0700
  Re: Type of a generic class? markspace <-@.> - 2012-08-02 14:08 -0700
    Re: Type of a generic class? Donkey Hottie <donkey@fredriksson.dy.fi> - 2012-08-03 02:27 +0300
      Re: Type of a generic class? Lew <lewbloch@gmail.com> - 2012-08-02 16:51 -0700
      Re: Type of a generic class? markspace <-@.> - 2012-08-02 20:08 -0700
        Re: Type of a generic class? Donkey Hottie <donkey@fredriksson.dy.fi> - 2012-08-03 17:25 +0300
  Re: Type of a generic class? Donkey Hottie <donkey@fredriksson.dy.fi> - 2012-08-04 13:46 +0300

csiph-web