So, I'm looking through a java library (JScience) after someone here thoughfully pointed me towards it for getting Vectors (mathematical ones, that is) in java.
Unfortunately, I've never seen anything in my life before like:
public static <F extends Field<F>> DenseVector<F> valueOf(F... elements)
as a method you can call in the DenseVector class. What...does that even mean. Is it returning a "<F extends Field<F>>
" (and if so, why does Eclipse think it's an input?)
http://jscience.org/api/org/jscience/mathematics/vector/DenseVector.html#valueOf(F...)
It really confuses me. I can't make a new DenseVector()
because only the super class has that, and it's protected, and trying to do DenseVector.valueOf()
apparently only works if I give it...that...weird thing as an input.
I've seen people having to instantiate methods when trying to instantiate objects (or something like that)...is that like that (or IS it that?)) What is the API trying to get me to do?
I'm kind of confused that I've learned java in school (and used it a bit at work, though we use a lot of differnet stuff besides just java), and never came across anything like this. What's it for? What's it trying to get me to do? Is it new? Old? Obscure?
-Jenny
You should be able to invoke this method to create a vector, like this:
In this example, the type argument
F
isReal
.Real
obeys the constraint "extends Field<F>
" because it implementsField<Real>
.For different applications, different fields are likely to be used. For example, security applications might use the
ModuloInteger
field. It's a little confusing because this is a mathematical field, not a "vector field" like one talks about in physics.By using type variables, this library helps to make sure you perform all operations within a given field. For example, given
v
declared as aDenseVector<Real>
like above, the compiler will complain if you try to multiply it by aComplex
number.