0922-----homework-part2---about simple collection and try catch and linked operate likes JQuery by self

  1 //define package
  2 package com.kai.li;
  3     
  4 //import packages and classes
  5 import java.util.List;
  6 import java.util.ArrayList;
  7  
  8 //about collection
  9 //joined in simple list
 10 //client
 11 public class Text2{
 12     public static void main(String[] args){
 13         System.out.println("Following is the first question.");
 14         List<Outter> list=new ArrayList<Outter>();
 15         Outter o1=new Outter();
 16         Outter o2=new Outter();
 17         Outter o3=new Outter();
 18         list.add(o1);
 19         list.add(o2);
 20         list.add(o3);
 21         System.out.println(list);
 22         Outter[] ox=new Outter[list.size()];
 23         ox=list.toArray(ox);
 24         System.out.println(ox);
 25         for(Outter lemp:list){
 26             System.out.println(lemp);
 27         }
 28         Outter o4=list.get(0);
 29         Outter o5=list.get(1);
 30         Outter o6=list.get(2);
 31         System.out.println(o4+" "+o5+" "+o6);
 32         Outter.ShapePara<Integer,Double> s1=()->System.out.println("hi...hi...");
 33         s1.toS();
 34         try{
 35 
 36             //A text of linked operate and implements by myself
 37 
 38             s1.link1().link2().link3();    
 39 
 40         }catch(Exception e){
 41             System.out.println("This a text about try catch.");
 42         }
 43         Outter.ShapePara<Integer,Double> s2=o4.new Circle<Integer,Double>(10,12.0,12.0); 
 44         System.out.println();
 45         //following are the lambda and linked,so ,you can add,then div,then sub...... shortly,following equals new ChildrenName();
 46         Outter.ShapePara<Integer,Double> s3=()->{};
 47         s3.link1().link2().link3();
 48     }
 49 }
 50 
 51 //interface and the class implenments it parts
 52 //following is the first interface part
 53 //Outter class
 54 class Outter{
 55     interface ShapePara<T1,T2>{
 56         public void haha();
 57         default public void toS(){
 58             System.out.println("I am sorry,I can't implements the generic's operate.");
 59         }
 60         default public ShapePara<T1,T2> link1(){
 61             
 62             toS();
 63             System.out.println(this+":This is the first object operate.");
 64             return this;
 65         }
 66         default public ShapePara<T1,T2> link2(){
 67             
 68             toS();
 69             System.out.println(this+":This is the second object operate.");
 70             return this;
 71         }
 72         default public ShapePara<T1,T2> link3(){
 73             
 74             toS();
 75             System.out.println(this+":This is the third object operate.");
 76             return this;
 77         }
 78     }
 79     class Circle<T1,T2> implements ShapePara<T1,T2>{
 80         public T1 radius;
 81         private T2 x;
 82         protected T2 y;
 83         Circle(T1 radius){
 84             this.radius=radius;
 85         }
 86         Circle(T1 radius,T2 x,T2 y){
 87             this(radius);
 88             this.x=x;
 89             this.y=y;
 90         }
 91         public void setX(T2 x){
 92             this.x=x;
 93         }
 94         public T2 getY(){
 95             return y;
 96         }
 97         public T1 getRadius(){
 98             return radius;
 99         }
100         public void setRadius(T1 radius){
101             this.radius=radius;
102         }
103         public void setCenter(T2 x,T2 y){
104             this.setX(x);
105             this.y=y;
106         }
107         public void haha(){}
108     }
109     //I can't implements the operate of getArea and getCircumference with the generic
110     class Operate{
111         public double getArea(double radius){
112             return Math.PI*Math.pow(radius,2);
113         }
114         public double getCircumference(double radius){
115             return 2*Math.PI*radius;
116         }
117     }    
118 }

 

posted @ 2016-09-22 21:40  火山林风  阅读(177)  评论(0编辑  收藏  举报