Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / May 2008

Tip: Looking for answers? Try searching our database.

Reified types and primitives

Thread view: 
Mark Space - 19 May 2008 04:50 GMT
Alex's Miller's blog talks about reified generics being on the radar for
Java 7.

http://tech.puredanger.com/java7/

I wonder if a way to specify a primitive as a type parameter would be
useful.  Boxing and unboxing does take time, and that could be
unacceptable for some types of applications.

The trick would be to find someway to represent something like:

public class Point2D<class T> {
  T x,y;

  // etc.
}

where T might be either double or float, for example.

(Note that "<class T>" is the proposed syntax for reified generics.)

There's already one primitive with a defined class type:  void.class.
Sun would have to define a some types of Class<?> to represent the new
types.  (Maybe "Class<Primitive>".)  And there'd have to be some
concensus on hierarchy, if any.

I'm not convinced a hierarchy of primitives is a good thing.  Is
"implements" used in parameterized types?  If not perhaps it could be
used to indicate a list, rather than a hierarchy.

public class Point2D<class T implements float.class, double.class> { //...
}

means pick on of those two.
Mark Space - 19 May 2008 05:14 GMT
> There's already one primitive with a defined class type:  void.class.
> Sun would have to define a some types of Class<?> to represent the new
> types.  (Maybe "Class<Primitive>".)  And there'd have to be some
> concensus on hierarchy, if any.

Oops, misspelled "consensus" and this should have gone in
c.l.j.programmer.  Sorry about that.
Roedy Green - 19 May 2008 18:35 GMT
On Sun, 18 May 2008 20:50:40 -0700, Mark Space
<markspace@sbc.global.net> wrote, quoted or indirectly quoted someone
who said :

>useful.  Boxing and unboxing does take time, and that could be
>unacceptable for some types of applications.

Eiffel has some way of treating primitives as Objects, but without the
overhead.  It might be productive to find out how their scheme works
to see if any of it would be applicable to Java.
Signature


Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com

Mark Space - 19 May 2008 20:47 GMT
> On Sun, 18 May 2008 20:50:40 -0700, Mark Space
> <markspace@sbc.global.net> wrote, quoted or indirectly quoted someone
[quoted text clipped - 6 lines]
> overhead.  It might be productive to find out how their scheme works
> to see if any of it would be applicable to Java.

I was thinking that with reifiable types, the class or object could get
a reference to a Class type that describes the type.  (I assume this is
what has to happen for reifiable types anyway.)

So for some class

public Point3D<class T implements double.class, float.class>
{
  T x, y, z;
}

the compiler will have to add a field for the class type.  This type
could be used to "treat primitives like objects."

It depends on exactly what operations one needs to perform on primitives
that are "like a class."  Determining those operations is probably the
hard part.

BTW, if Point3D is reifiable, what is the class type?  I don't think
it's Point3D anymore.  So, can I get it's type with a literal still?
Will something like "this.class" be available? Or will I have to call
"this.getClass()?"  It seems like the latter is also a requirement.
Plus, it might be an error to invoke a class literal on a class that
hasn't been parameterized yet.

Point3D.class == we don't know yet, throw an error.

This reifiable proposal for Java 7 has some funny corners.

(This one, I mean:

<http://tech.puredanger.com/java7/#reified> )
Lew - 20 May 2008 02:25 GMT
> There's already one primitive with a defined class type:  void.class.

'void' is not a primitive.
<http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.2>

'void' is not a type.
<http://java.sun.com/docs/books/jls/third_edition/html/statements.html#14.8>
> ... void is not a type ...

'Void' is a type.
<http://java.sun.com/javase/6/docs/api/java/lang/Void.html>

Signature

Lew

Mark Space - 20 May 2008 03:50 GMT
>> There's already one primitive with a defined class type:  void.class.
>
> 'void' is not a primitive.
> <http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.2>

Yeah, that's true.  Bad choice of words on my part.

> 'void' is not a type.
> <http://java.sun.com/docs/books/jls/third_edition/html/statements.html#14.8>
>
>> ... void is not a type ...

Well... it's talking about expressions there, and casts in particular.

  "Unlike C and C++, the Java programming language allows only certain
forms of expressions to be used as expression statements. Note that the
Java programming language does not allow a "cast to void"-void is not a
type-so the traditional C trick of writing an expression statement such as:

    (void) ... ;           // incorrect!"

By contrast, in method declarations, their "ResultType" can be void.  I
think outside of the language spec itself, "type" is just a handy word
here to refer to a concept which includes void.

<http://java.sun.com/docs/books/jls/third_edition/html/classes.html#8.4>

> 'Void' is a type.
> <http://java.sun.com/javase/6/docs/api/java/lang/Void.html>

Void is a class. :)

  "The Void class is an uninstantiable placeholder class to hold a
reference to the Class object representing the Java keyword void."

Note they refer to void as a keyword.

I think however that referring to void as a type is not playing too fast
and loose with the language.  It's a type, it just can't be used in
expressions (the only one that can't).

"Type or void" might be a better way of expressing what I'm trying to
say here. So might "result type."   But they're also a tad clumsy in
English.  I think some latitude is needed, when not writing a spec, as
to how concepts are referred to, as long as the concepts are clear.

I may have crossed the line from clarity to obtuseness by referring to
void as a type without any other discussion how I'm using that term, but
I don't think the word "type" should never be applied to "void" because
of that.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.