0

What do these lines of code do?

private interface ComparisonCallback<ComparisonT>
{
    public ComparisonT getComparisonValue(CVRDataElement e);
}

followed by this method declaration:

public <ComparisonType> List<MyDataTable> getGenericSubTable(ComparisonCallback<ComparisonType> cc)

Specifically, I don't understand the ComparisonType tag - does this have to do with generics?

7
  • That syntax doesn't look quite right. Are you sure that's correct? Commented Jul 14, 2010 at 3:02
  • @Joe that is the correct syntax for generics in Java (except for the missing space...) Commented Jul 14, 2010 at 3:04
  • Shouldn't ComparisonT and ComparisonType be the same word instead of different? Commented Jul 14, 2010 at 3:08
  • Not to mention, the method declaration isn't actually IN the interface. This has confusion written all over it. Commented Jul 14, 2010 at 3:12
  • no, ComparisonT and ComparisonType are different words. This is code that someone rewrote for me (I am new to Java and write very basic code) and gave back. I am trying to understand it now. Commented Jul 14, 2010 at 3:16

2 Answers 2

1

does this have to do with generics

Yes. You can read up about generics here.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the link - what I had read previously on generics didn't explain type parameters.
0

The first interface is the definition of a callback function to be used in the getGenericSubTable method.

The getGenericSubTable parameterizes the return value of the callback function, so it's saying that to do what it needs to do it needs the callback function but that it doesn't care what the type of its return type is.

What it probably means is that you use the callback to return the object that you want it to use for comparison from the CRVDataElement object.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.