package hfd
//需求:
//完成一个功能,让所有的字符串都能调用isPhone方法,来校验自己是不是一个手机号
object Test37_1 {
class StrongString(val str: String) {
//开始你的代码
def isPhone(): Boolean = {
val reg = "1[3-9]\\d{9}".r
reg.matches(str)
}
}
//定义一个特殊的转换函数,把str===>StrongString的对象
def tranform(str: String): StrongString = {
new StrongString(str)
}
def main(args: Array[String]): Unit = {
val str = "12345678"
// println(isPhone(str))
// println(isPhone("abc"))
println(tranform("abc").isPhone())
// println((new StrongString(str)).isPhone())
// str.isPhone()//==>true
// "136a".isPhone()//==>false
}
}
Scala的隐式转换(1)
2401_833788052024-12-10 9:17
相关推荐
Risehuxyc11 小时前
为什么php结束符?>省略不写旖旎夜光12 小时前
【C 语言】(二)模拟实现 strlen、strcpy、strcmp、strstr、memcpy、memmovecodeejun13 小时前
每日一Go·MySQL-22、幻读、不可重复读、脏读实战演示云草桑13 小时前
C#入坑JAVA 潜规则 API Get 多参数 Spring Boot与Spring Cloud 区别 入门系列4码途行者1 天前
每天10分钟学Go:第17课 接口interface-只规定“能做什么“,不管它是什么头发还在的女程序员1 天前
Java充电桩平台源码解析:枪口状态、上报时间与页面刷新怎样协同timeDifference₇1 天前
Python Vibe Coding实操实验报告geovindu1 天前
python:DecisionTreegeovindu1 天前
python: Decision Tree Regressor炸膛坦客1 天前
单片机/C/C++八股:(三十七)指针数组 和 数组指针