Javaaaaaaaaaaaaaaaaaaaaa
parent
6621d48a07
commit
43de41eee1
@ -0,0 +1,18 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project-shared-configuration>
|
||||||
|
<!--
|
||||||
|
This file contains additional configuration written by modules in the NetBeans IDE.
|
||||||
|
The configuration is intended to be shared among all the users of project and
|
||||||
|
therefore it is assumed to be part of version control checkout.
|
||||||
|
Without this configuration present, some functionality in the IDE may be limited or fail altogether.
|
||||||
|
-->
|
||||||
|
<properties xmlns="http://www.netbeans.org/ns/maven-properties-data/1">
|
||||||
|
<!--
|
||||||
|
Properties that influence various parts of the IDE, especially code formatting and the like.
|
||||||
|
You can copy and paste the single properties, into the pom.xml file and the IDE will pick them up.
|
||||||
|
That way multiple projects can share the same settings (useful for formatting rules for example).
|
||||||
|
Any value defined here will override the pom.xml file value but is only applicable to the current project.
|
||||||
|
-->
|
||||||
|
<netbeans.hint.jdkPlatform>JDK_20__System_</netbeans.hint.jdkPlatform>
|
||||||
|
</properties>
|
||||||
|
</project-shared-configuration>
|
@ -0,0 +1,23 @@
|
|||||||
|
/*
|
||||||
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||||
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||||
|
*/
|
||||||
|
package edu.slcc.asdv.caleb.gemericrules;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author caleb
|
||||||
|
*/
|
||||||
|
public class GenericRule4 {
|
||||||
|
public static void f1(ArrayList<?> list) {
|
||||||
|
System.out.println(list.size());
|
||||||
|
///list.add(new Integer(5));
|
||||||
|
}
|
||||||
|
public static void main(String[] args)
|
||||||
|
{
|
||||||
|
f1(new ArrayList<Integer>());
|
||||||
|
f1(new ArrayList<Double>());
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
/*
|
||||||
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||||
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||||
|
*/
|
||||||
|
package edu.slcc.asdv.caleb.gemericrules;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author caleb
|
||||||
|
*/
|
||||||
|
public class GenericRule5 {
|
||||||
|
public static void main(String[] args)
|
||||||
|
{
|
||||||
|
List<?> list1 = new ArrayList<Integer>();
|
||||||
|
ArrayList<?> list2 = new ArrayList<Double>();
|
||||||
|
ArrayList<?> list3 = new ArrayList<String>();
|
||||||
|
//list3.add("abc");
|
||||||
|
System.out.println(list3.size());
|
||||||
|
System.out.println(list3.subList(0, 0));
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||||
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||||
|
*/
|
||||||
|
package edu.slcc.asdv.caleb.gemericrules;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import static java.util.Collections.list;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author caleb
|
||||||
|
*/
|
||||||
|
public class GenericRule6 {
|
||||||
|
public static void f6(List<? extends A> list) {
|
||||||
|
System.out.println(list.size());
|
||||||
|
}
|
||||||
|
public static void main(String[] args)
|
||||||
|
{
|
||||||
|
List<A> list1 = new ArrayList<>();
|
||||||
|
list1.add (new C());
|
||||||
|
list1.add (new B());
|
||||||
|
f6(list1);
|
||||||
|
|
||||||
|
ArrayList<B> list2 = new ArrayList<>();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//class A{}
|
||||||
|
//class B extends A{}
|
||||||
|
//class C extends B{}
|
@ -0,0 +1,44 @@
|
|||||||
|
/*
|
||||||
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||||
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||||
|
*/
|
||||||
|
package edu.slcc.asdv.caleb.gemericrules;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import static java.util.Collections.list;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author caleb
|
||||||
|
*/
|
||||||
|
public class GenericRule7 {
|
||||||
|
|
||||||
|
public static void f6(List<? extends A> list)
|
||||||
|
{
|
||||||
|
System.out.println(list.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args)
|
||||||
|
{
|
||||||
|
List<A> list1 = new ArrayList<>();
|
||||||
|
list1.add(new C());
|
||||||
|
list1.add(new B());
|
||||||
|
|
||||||
|
List<? extends A> list = list1;
|
||||||
|
|
||||||
|
ArrayList<B> list2 = new ArrayList<>();
|
||||||
|
list1.add(new A());
|
||||||
|
list = list2;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class A {
|
||||||
|
}
|
||||||
|
|
||||||
|
class B extends A {
|
||||||
|
}
|
||||||
|
|
||||||
|
class C extends B {
|
||||||
|
}
|
@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||||
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||||
|
*/
|
||||||
|
package edu.slcc.asdv.caleb.gemericrules;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author caleb
|
||||||
|
*/
|
||||||
|
public class GenericRule8<T1> {
|
||||||
|
|
||||||
|
// List<? extends T1> lista = new ArrayList<String>();
|
||||||
|
|
||||||
|
public static <T2> void f8(List<? extends T2> list)
|
||||||
|
{
|
||||||
|
System.out.println(list.size());
|
||||||
|
//list.add(new C());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args)
|
||||||
|
{
|
||||||
|
list<A> list1 = new ArrayList<>();
|
||||||
|
list1.add(new C());
|
||||||
|
list1.add(new B());
|
||||||
|
f8(list1);
|
||||||
|
|
||||||
|
ArrayList<B> list2 = new ArrayList<>();
|
||||||
|
list2.add(new A());
|
||||||
|
f8(list2);
|
||||||
|
|
||||||
|
ArrayList<String> list3 = new ArrayList<String>();
|
||||||
|
list3.add("abc");
|
||||||
|
f8(list3);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue