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

  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 }

 

转载于:https://www.cnblogs.com/kaililikai/p/5898070.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值