Question

Java Question. Please provide a correct solution with steps. Will provide a thumbs up for correct...

Java Question. Please provide a correct solution with steps. Will provide a thumbs up for correct solution. Answer as soon as possible.

What is type argument inference? Why does a generic method look like an indefinite overloaded method?

0 0
Add a comment Improve this question Transcribed image text
Answer #1
Type argument inference is a process performed by the compiler to determine the actual type argument for a type parameter when invoking in a generic method.

Example of generic method:
-----------------------------
static <T> T add(T a1, T a2) {
    return a1+a2;
}

Example of overloaded methods according to above generic method:
------------------------------------------------------------------
static int add(int a1, int a2){
    return a1+a2;
}

static float add(float a1, float a2){
    return a1+a2;
}

.....
.....

static String add(String a1, String a2){
    return a1+a2;
}


So, From the above we can say that if we write all indefinite overloaded methods then that will equals to the above genetic method.
Add a comment
Know the answer?
Add Answer to:
Java Question. Please provide a correct solution with steps. Will provide a thumbs up for correct...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT