Meaning of Java syntax: class A extends B<C> [duplicate] - java

This question already has answers here:
The syntax <T extends Class<T>> in Java
(3 answers)
Closed 8 years ago.
What does this syntax mean in Java: class A extends B<C>? I came across this in an Android library and couldn't find it on google.
More specifically, this is what I had come across:
public class PullToRefreshExpandableListView extends PullToRefreshAdapterViewBase<ExpandableListView>

Generics with Class and Interfaces
Genrics is one of the core feature of Java programming and it was introduced in Java 5.
We can define our own classes and interfaces with generics type.
A generic type is a class or interface that is parameterized over types. We use angle brackets (<>) to specify the type parameter.
Please refer this link for more information

Related

Can we use multiple extends of class in java selenium? [duplicate]

This question already has answers here:
Java Multiple Inheritance
(17 answers)
Closed 2 years ago.
Please explain how to extend two classes from different packages.
public class Animal extends Herbivores extends Omnivores {
}
Multiple Inheritance or Diamond Inheritance is a feature of object oriented concept, where a class can inherit properties of more than one parent class.
Java does not support that.
There are multiple resources over the net which tells you the problem that arises if you are allowed to do that.
Coming to your problem, it seems to me like a fault in Design.
Animal should be a parent type rather than a child type. Both Herbivores and Omnivores are animals. Whereas an animal doen't necessary have to be either. It can be a carnivore also.

gwt interface HostedModeOptions extends more than 1 class [duplicate]

This question already has answers here:
Can an interface extend multiple interfaces in Java?
(7 answers)
Closed 5 years ago.
i work in GWT. The Devmode class in gwt has an interface in it called 'HostedModeOptions'. But HostedModeOptions extends more than 1 class like :
protected interface HostedModeOptions extends HostedModeBaseOptions, CompilerOptions {
ServletContainerLauncher getServletContainerLauncher();
String getServletContainerLauncherArgs();
void setServletContainerLauncher(ServletContainerLauncher scl);
void setServletContainerLauncherArgs(String args);
}
How is this possible in java 7 ? As far as i know we cannot extend more than 1 class at a time in java 7.
Can anyone explain please .
You cannot extend other more than one class however you can implement many interfaces. If you are developing an interfacing you can make use of other interface and can extend many other interfaces.
They are all interfaces and not classes.. An interface can extends many interfaces. This facility is there from very first version of Java.
If you have any doubts regarding ambiguity, below link might help a bit
Can an interface extend multiple interfaces in Java?

Why only java.lang. Object is given superclass in java? [duplicate]

This question already has answers here:
Why Object class is Superclass in java [closed]
(4 answers)
Closed 6 years ago.
Is there any reason sun microsystems make Object for all javaclass for superclass. I face the question my last interview. I hope, I can find answers here
Thanks
Following could be the reasons for this design decision,
By having the Object as the super class of all Java classes, without knowing the type we can pass around objects using the Object declaration.
Before generics was introduced, imagine the state of heterogeneous Java collections. A collection class like ArrayList allows to store any type of classes. It was made possible only by Object class hierarchy.
The other reason would be to bring a common blueprint for all classes and have some list of functions same among them. I am referring to methods likehashCode(), clone(), toString() and methods for threading which is defined in Object class.
Please check the below link. I hope it will answer your question.
Why object is super class in JAVA

Why java does not support multiple inheritance? [duplicate]

This question already has answers here:
Why is there no multiple inheritance in Java, but implementing multiple interfaces is allowed?
(21 answers)
Closed 7 years ago.
In java by default all classes are inherit from Object class and even we can also inherit the classes.
class A{ // default **Object class** is extended
}
class B extends A{
//default **Object class** is extended and also **class A** extended.
}
Then why we say that java doesn't support multiple inheritance through classes?
It is just to remove ambiguity, because multiple inheritance can cause
ambiguity in few scenarios. One of the most common scenario is Diamond
problem.
Look at this page : http://www.instanceofjava.com/2014/12/why-java-does-not-supports-multiple.html

Java - Extending Unknown Classes [duplicate]

This question already has answers here:
Extend a generic type in Java
(2 answers)
Closed 8 years ago.
I wanted to create a class that can extend an unknown class that is provided at runtime. I thought that I could do something like this:
public class Foo<T extends Bar> extends T {}
but that doesn't work. Is there a way to do this?
Not without some crazy runtime code generation. Java's generics are not the same sort of thing as C++'s templates: Internally, T is simply treated as an Object, and up- and down-casted as necessary for the benefit of your code. So while a C++ template is instantiated for a particular T, and can decide at compile-time whether that works, in Java the machinery underlying inheritance requires that the actual base class be decided upon in the class definition itself.

Categories