Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within OCPJP
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Programmer Certification (OCPJP)
Syntax required to call method with Type parameters
Thomas Hauck
Ranch Hand
Posts: 106
posted 8 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Question:
What is the correct syntax required to call the method with type parameters on line 1?
Can the method defined on line 1 be called from within main(
String
args[]) on line 2?
class C { public void mCPublic() { System.out.println("Within mCPublic ");} protected void mCProtected() { System.out.println("Within mCProtected()"); } void mCDefault() { System.out.println("Within mCDefault"); } private void mCPrivate() { } } interface I { void mI(); } class CT extends C implements I { public void mI() { System.out.println("Within method mI() of CT extends C implements I"); } } class Test { <T extends C & I> void test(T t) { //line 1 t.mI(); t.mCPublic(); t.mCProtected(); t.mCDefault(); } public static void main(String args[]){ Test t1 = new Test(); C c1 = new C(); I i1 = new CT(); CT ct1 = new CT(); ct1.mCDefault(); ct1.mI(); // line 2: call method test (on line 1) here } }
Sergej Smoljanov
Ranch Hand
Posts: 472
10
posted 8 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
t1.test(ct1);
https://docs.oracle.com/javase/specs/jls/se7/html/jls-4.html#jls-4.4
may be this one help it has same example
you can call on instance
Test
t1
.
you must pass argument than extends C and implements I this one is CT class that
ct1
Thomas Hauck
Ranch Hand
Posts: 106
posted 8 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Thank you for your reply.
What's a year in metric? Do you know this metric stuff tiny ad?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
JLS Types, Values, Variables - Error?
what happen if all constructor of a class be declared as private?
String reference remains same during clone()
Object constructor and initialization
Confusion.
More...