• 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
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Generic Declaration

 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear All,

please find the one below from devaka coorey simulator



I have compiled above code to see what happened. I don't understand compiler error that said

type parameter K is not within its bound and type parameter ? super V is not within its bound


what is error exactly mean and I'm not clear enough how to deal with question like this.

really appreciate for any kind help. thank you.
 
author
Posts: 23956
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

what is error exactly mean and I'm not clear enough how to deal with question like this.



This option...



is just too weird. Hopefully, this will never be encountered in real code. My main issue is this generic method declares a generic type K, but the method is in a class that also has a generic type K. It's just too confusing to figure out which K is which...

But to answer your question...

This generic method is defining a new type K (which is unbounded), and then declares a method that takes a Fractal of type K, and returns a Fractal of type K. Unfortunately, Fractual can't take an unbounded type. It can only work with types that extend Number.

This is what the compiler meant by "type parameter K is not within its bound". The unbounded type K can't be used as part of Fractal.

Henry
 
Marshal
Posts: 7266
1397
IntelliJ IDE jQuery Eclipse IDE Postgres Database Tomcat Server Chrome Google App Engine
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Henry Wong wrote:My main issue is this generic method declares a generic type K, but the method is in a class that also has a generic type K. It's just too confusing to figure out which K is which...




The Explanation for this question says:

When you have declare a generic type for a method, as same as to the generic type declare for the class, the class-generic-type will be shadowed by the, method's-generic-type. Therefore, for this method, K is just a new generic type.



Hmmm,.... Is this question too much tough for SCJP? Let me know, if it is, I'll remove this question from the next version of ExamLab.

Devaka.
 
Vierda Mila
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Hmmm,.... Is this question too much tough for SCJP?



dear Devaka,

I don't know about others thinks but I have to reschedule my exam after trying your simulator . in another mock I can gained 75%-80% but in yours I never get beyond 55% thats mean I'm fail in exam

but really appreciate for this simulator.it makes me to learn a lot. and thanks for make it free. keep a great job man
 
My honeysuckle is blooming this year! Now to fertilize this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic