public interface stu {
public Integer opstu(Integer a,String b);}
public class opstulmpl implements stu {@Override
public Integer opstu(Integer a,String b){return a;}}
public class TestDemo {
public static void main(String[] args){
stu salary=(Integer a,String content)->{if(content.equals("初中")&a==18){return2000;}elseif(content.equals("高中")&a==20){return2200;}elseif(content.equals("大专")&a==21){return2400;}elseif(content.equals("本科")&a==24){return3000;}else{return0;}};
System.out.println(salary.opstu(18,"初中"));
//偏函数def funPartitional:PartialFunction[String,Int]={case"hello"=>1case"World"=>2case _ =>0}// val num=funPartitional("djflsf")// println(num)// val worlds=List("hello","world","gree","kb09")// val ints: List[Int] = worlds.collect(funPartitional)// worlds collect funPartitional foreach println// def diao:PartialFunction[String,Int]={// case "hehe"=>2// case "niu"=>1// case _ => 0// }// println(diao("hehe"))// println(diao("niu"))// println(diao("djfdsf"))//// def funGender:PartialFunction[String,Int]={// case "male"=>1// case "female"=>0// case "男"=>1// case "女"=>0// case _ => -1// }// println(funGender("男"))// println(funGender("女"))// println(funGender("fsdffs"))def funTupple:PartialFunction[Char,(Char,Int)]={case'A'=>('A',1)case'B'=>('B',1)case _=>('X',1)}// val tuple:(Char,Int)=funTupple('A')// print(tuple)val chars=List('A','B','C','D')val tuples:List[(Char,Int)]=chars.collect(funTupple)//tuples.foreach(tp=>println(tp._1))def fun2:PartialFunction[Any,Int]={case i:Int=>i
case _=>0}var list=List("a","c",2,2.5,3,4,6)
list.collect(fun2).foreach(println)