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


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

Checked casting with Generics

Path csiph.com!weretis.net!feeder4.news.weretis.net!news.albasani.net!.POSTED!not-for-mail
From Martin Gregorie <martin@mydomain.invalid>
Newsgroups comp.lang.java.programmer
Subject Checked casting with Generics
Date Wed, 4 Jul 2018 19:57:17 +0000 (UTC)
Organization albasani.net
Lines 37
Message-ID <phj8qt$hpp$1@news.albasani.net> (permalink)
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding 8bit
X-Trace news.albasani.net PIVyuMYDeTCiuWXYckeOgEW+/dtZJ1ipODE/Zu/ilKWaXX5UDiwSeQez+KZKONuDJzGIAMYqTnBEjLH1ylA4Ew==
NNTP-Posting-Date Wed, 4 Jul 2018 19:57:17 +0000 (UTC)
Injection-Info news.albasani.net; logging-data="AooD9izgjif3BimWLMayHyZQyhXH5tMKsXxdWppkq2aX3vVdUM65FZvcFChBIiaz0NS/NDopSZjLFDdt+8qLdsSFQ8odNzY6yWX1MHQNleBdUAZdVestZMqLe7GKMlKy"; mail-complaints-to="abuse@albasani.net"
User-Agent Pan/0.145 (Duplicitous mercenary valetism; d7e168a git.gnome.org/pan2)
Cancel-Lock sha1:IqB72NzBS5pjj5b6/9i1UI/MUn0=
Xref csiph.com comp.lang.java.programmer:38470

Show key headers only | View raw


I have a problem with casting Generics. Been searching around but haven't 
found and solutions that work (and even 'solutions' that don't 
compile(!). Anyway, here's the problem:

I'm handling email using javax.mail classes. The code was originally 
written with Java 6 and it has run untouched until now, when I changed 
some code and recompiled the app using Java 8 (OpenJava 1.8.0). Its all 
fine apart from a couple of casts in unrelated code.

The immediate problem is that I need to handle the list of header in part 
of a multipart message. The statement: 

   Enumeration<Header> e = m.getAllHeaders();

compiled without any fuss under Java 6, but when compiled now it issues a 
warning: 
    [javac] /home/marchive/marchive/org/gregorie/mailarchive/internals/
HeaderBlock.java:52: warning: [unchecked] unchecked conversion
    [javac]          Enumeration<Header> e = m.getAllHeaders();
    [javac]                                                 ^
    [javac]   required: Enumeration<Header>
    [javac]   found:    Enumeration

Writing it as a simple cast by adding (Enumeration<Header>) after the 
assignment operator has no effect and nothing I've adapted from examples 
using isinstanceof or inherited Class.isInstance() does anything except 
throw compilation syntax errors.

I can run with it like this, but would really like to handle this 
unchecked conversion, partly to get rid of the compiler warning and 
partly so I understand how it should be done.



-- 
Martin    | martin at
Gregorie  | gregorie dot org

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


Thread

Checked casting with Generics Martin Gregorie <martin@mydomain.invalid> - 2018-07-04 19:57 +0000
  Re: Checked casting with Generics Eric Sosman <esosman@comcast-dot-net.invalid> - 2018-07-04 17:22 -0400
    Re: Checked casting with Generics Eric Sosman <esosman@comcast-dot-net.invalid> - 2018-07-04 17:37 -0400
      Re: Checked casting with Generics Martin Gregorie <martin@mydomain.invalid> - 2018-07-04 23:03 +0000
      Re: Checked casting with Generics Martin Gregorie <martin@mydomain.invalid> - 2018-07-05 15:38 +0000
    Re: Checked casting with Generics Martin Gregorie <martin@mydomain.invalid> - 2018-07-04 22:56 +0000

csiph-web