Skip to content

Commit 96f49a9

Browse files
RameshRamesh
authored andcommitted
feb8
1 parent 9f01863 commit 96f49a9

8 files changed

Lines changed: 74 additions & 0 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" path="src"/>
4+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
5+
<classpathentry kind="output" path="bin"/>
6+
</classpath>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>GenericsDemo</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
</buildSpec>
14+
<natures>
15+
<nature>org.eclipse.jdt.core.javanature</nature>
16+
</natures>
17+
</projectDescription>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
eclipse.preferences.version=1
2+
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
4+
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
5+
org.eclipse.jdt.core.compiler.compliance=1.8
6+
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
7+
org.eclipse.jdt.core.compiler.debug.localVariable=generate
8+
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
9+
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
10+
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
11+
org.eclipse.jdt.core.compiler.source=1.8
1.09 KB
Binary file not shown.
711 Bytes
Binary file not shown.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Code to use the generic class.
3+
*/
4+
public class GenericDemo
5+
{
6+
public static void main(String[] args)
7+
{
8+
useInteger();
9+
useString();
10+
}
11+
12+
private static void useInteger()
13+
{
14+
MyGeneric<Integer> myGeneric=new MyGeneric<Integer>();
15+
myGeneric.add(2);
16+
//m.add("peter");//Compile time error
17+
System.out.println(myGeneric.get());
18+
}
19+
20+
private static void useString()
21+
{
22+
MyGeneric<String> myGeneric=new MyGeneric<String>();
23+
myGeneric.add("Ram");
24+
System.out.println(myGeneric.get());
25+
}
26+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class MyGeneric<T>
2+
{
3+
T obj;
4+
5+
void add(T obj)
6+
{
7+
this.obj = obj;
8+
}
9+
10+
T get()
11+
{
12+
return obj;
13+
}
14+
}
66.2 KB
Binary file not shown.

0 commit comments

Comments
 (0)