请问怎样把这函数转为Kotlin 码?


#1

@SuppressWarnings(“unchecked”)
public static List getSystemPort(){
List systemPorts = new ArrayList<>();
//获得系统可用的端口
Enumeration portList = CommPortIdentifier.getPortIdentifiers();
while(portList.hasMoreElements()) {
String portName = portList.nextElement().getName();//获得端口的名字
systemPorts.add(portName);
}
System.out.println(“系统可用端口列表:”+systemPorts);
return systemPorts;
}

谢谢!


#2

val systemPort: List
get() = CommPortIdentifier.getPortIdentifiers().map(i -> i.getName()).toList


京ICP备16022265号-2 Kotlin China 2017 - 2018