Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #8561
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!news-peer.in.tum.de!news.belwue.de!rz.uni-karlsruhe.de!feed.news.schlund.de!schlund.de!news.online.de!not-for-mail |
|---|---|
| From | Philipp Kraus <philipp.kraus@flashpixx.de> |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: generic constructor call with concret type |
| Date | Wed, 5 Oct 2011 11:58:33 +0200 |
| Organization | 1&1 Internet AG |
| Lines | 48 |
| Message-ID | <j6h9o9$4np$1@online.de> (permalink) |
| References | <j6h246$uhn$1@online.de> <0dba7690-f51d-4b1f-bd59-92463784de71@20g2000yqq.googlegroups.com> |
| NNTP-Posting-Host | p3ee28ca0.dip0.t-ipconnect.de |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=iso-8859-1; format=flowed |
| Content-Transfer-Encoding | 8bit |
| X-Trace | online.de 1317808714 4857 62.226.140.160 (5 Oct 2011 09:58:34 GMT) |
| X-Complaints-To | abuse@einsundeins.com |
| NNTP-Posting-Date | Wed, 5 Oct 2011 09:58:34 +0000 (UTC) |
| User-Agent | Unison/2.1.5 |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:8561 |
Show key headers only | View raw
On 2011-10-05 11:22:50 +0200, Robert Klemme said:
> @SuppressWarnings("unchecked")
> public Run(Class<? extends T> cl) {
> if (cl == Float.class) {
> helper = (Inner<T>) new DoFloat();
> } else if (cl == Double.class) {
> helper = (Inner<T>) new DoDouble();
> } else {
> throw new IllegalArgumentException("Invalid type: " + cl);
> }
> }
>
> @Override
> public T doSomething() {
> return helper.doAnother();
> }
>
> // Test
> public static void main(String[] args) {
> final Base<Double> rd = new Run<Double>(Double.class);
> final Base<Float> rf = new Run<Float>(Float.class);
> System.out.println("Double: " + rd.doSomething());
> System.out.println("Float: " + rf.doSomething());
>
> final Base<Integer> ri = new Run<Integer>(Integer.class);
> System.out.println("Integer: " + ri.doSomething());
>
> // final Base<Integer> wontCompile = new Run<Integer>(Double.class);
> }
> }
so I need a parameter for the type
> Btw, what do you need that for?
See my posting some days ago. I use a JNI call with C++ templates so I
must set the template
parameter on compile-time. Within the JNI call I can't determine the
generic argument of the
instantiated java object (because it is set on java-compile-time). So I
create dual JNI calls one
for float and one for double, but I must decide on the java ctor call
if I instantiate the float or double
object, you do this in the with if(cl == Float.Class), in my source
code the DoFloat is the JNI call
for the C++ template float (otherwise the double).
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar
generic constructor call with concret type Philipp Kraus <philipp.kraus@flashpixx.de> - 2011-10-05 09:48 +0200
Re: generic constructor call with concret type Robert Klemme <shortcutter@googlemail.com> - 2011-10-05 02:22 -0700
Re: generic constructor call with concret type Philipp Kraus <philipp.kraus@flashpixx.de> - 2011-10-05 11:58 +0200
Re: generic constructor call with concret type Robert Klemme <shortcutter@googlemail.com> - 2011-10-05 22:14 +0200
csiph-web