Results 1 to 3 of 3
Thread: Nested generics and ugly syntax
- 05-23-2010, 01:17 PM #1
Member
- Join Date
- May 2010
- Posts
- 1
- Rep Power
- 0
Nested generics and ugly syntax
While I know that generics will always be somewhat ugly in syntax, there are limits to what is feasible for programming. I wonder if the following could not be simplified, e.g. make part of it just copy its generics from another class.
I'm doing mathematical simulations over certain (finite) fields, with different internal datatypes. So I work with generics: Field<ElementType,VectorType> can be- Field<Byte,byte[]> for small fields,
- Field<Short,short[]> for large fields,
- Field<Boolean,BitSet> for the binary field,
When considering stuctures over those fields, things seems to get arbitrary ugly. Projective points are just ProjectivePoint<ElementType, VectorType, Field<ElementType, VectorType>, projective lines are similarly ProjectiveLine<ElementType, VectorType, Field<ElementType, VectorType>, and the projective space is then ProjectiveSpace<ProjectivePoint<ElementType, VectorType, Field<ElementType, VectorType>, ProjectiveLine<ElementType, VectorType, Field<ElementType, VectorType>>, Field<ElementType, VectorType>, ElementType, VectorType>.
And it gets even worse. Now I had to type ElementType and VectorType 6 times, but for embedding projective spaces in eachother, I have to type it 16 times. And it goes up.
Am I doing this wrong, or do you see any way I could do this more efficient? I don't mind a long header, but I'd like to make it simple for people to contribute to my code. If GF implements Field<Byte,byte[]>, is there any way I can type new ProjectiveLine<GF>(parameters), rather than ProjectiveLine<Byte,byte[],GF>?
- 05-25-2010, 01:07 AM #2
Senior Member
- Join Date
- Mar 2010
- Posts
- 266
- Rep Power
- 4
i'm not sure I understand your problem 100%, but maybe this is helpful:
Java Code:class Field<ElementType, VectorType> { //... } class GF extends Field<Byte, byte[]> { //... } class Test { GF gf = new GF(); // no need for parameters here at all }
- 05-26-2010, 04:06 AM #3
Senior Member
- Join Date
- Jan 2009
- Posts
- 671
- Rep Power
- 5
I guess if I were lazy and I were doing this, ....and I am in fact lazy, I'd make the generic key off only a single type. So instead of using Byte and byte[], I'd be lazy and just use Byte, and then use Byte[].
Java Code:public class Junk<T extends Number> { public void stuff(T myT, T[] myTArray) { ...myT.doubleValue()..... for(T thisT : myTArray) { ...thisT.doubleValue().... } } }
Similar Threads
-
Generics
By bschmitt78 in forum Advanced JavaReplies: 3Last Post: 03-16-2010, 02:21 AM -
Ugly XML to parse
By JohnST in forum New To JavaReplies: 2Last Post: 01-03-2010, 04:48 PM -
generics
By tascoa in forum Forum LobbyReplies: 2Last Post: 10-09-2008, 07:58 PM -
Help w/ generics
By Hollywood in forum New To JavaReplies: 2Last Post: 02-16-2008, 03:08 AM -
Generics
By sireesha in forum New To JavaReplies: 2Last Post: 01-10-2008, 11:08 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks