I need a FtpEndpoint that is a generic class:
So I make a variable of the desired type and call the method:
But now the returned value is of type FtpEndpoint instead of type FtpEndpoint<FTPFile> (Warning: Type safety: The expression of type FtpEndpoint needs unchecked conversion to conform to FtpEndpoint<FTPFile>).
I thought I had to do something like
but this is causing a compile error: "FtpEndpoint cannot be resolved to a variable"
How can I correctly call a method like this with generics?
Brian Burress wrote:For the code that gives you a warning, is the returned object what you expect? If so, then either try casting it to the type needed -or- ignore the warning (I am taking your wording literally - if it is a warning and you have verified the behavior is ok then you are good).
Yes, the returned object is what I expect, I could cast it or ignore the warning. But I thought a advantage of using generics was to not having to cast in cases like this?
Wendy Gibbons wrote: it is very unlikely to be returning a FtpEndpoint<FTPFile>, as generics don't exist at runtime.
Have you tried looking at the source for camel?
I can remove the generic from the variable type like this:
But then I get the Warning: FtpEndpoint is a raw type. References to generic type FtpEndpoint<T> should be parameterized
The source for the method I like to call is:
But I don't see how this brings me any further.
"Basically the guys is screwed in Java generics unless he casts or not uses the generics.
He wants to use a “class” parameter that itself is generic and existing java does not allow that.
You can do things like assign to non generic variable and then use that to assign to what he needs or possibly use a <?> wild card.