我试图使用模式匹配找到scala中列表的最后一个元素.我试过以下代码
def last[A](list: List[A]):A = list match {
case head :: Nil => head
case head :: tail => last(tail)
case _ => Nil
}
Run Code Online (Sandbox Code Playgroud)
最后一种情况,即case _ => Nil抛出错误,因为类型不匹配(找到Nil.type需要A)
我知道这个问题可以使用其他方法解决,但只使用模式匹配是否有办法解决这个问题?
因为列表是泛型类型所以我不能用类型A的默认值替换Nil,它只能在运行时确定.
删除这一行:case _ => Nil 显然正在工作,但警告说在Nil参数的情况下会失败.
那么,在这种情况下如何处理Nil参数呢?
我正在尝试在詹金斯创建一个Maven项目.该代码位于Git存储库中,该存储库使用非标准端口1754.
端口详细信息已存在于配置文件中,但jenkins中的git插件无法连接.它给端口22带来了错误.
添加以下网址后,Jenkins(Git部分)会出现以下错误:gitolite@10.115.2.110:AutomationCode
Failed to connect to repository : Command "/usr/bin/git -c
core.askpass=true ls-remote -h gitolite@10.115.2.110:AutomationCode
HEAD" returned status code 128:
stdout:
stderr: ssh: connect to host 10.115.2.110 port 22: Connection refused
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Run Code Online (Sandbox Code Playgroud)
当我直接从终端克隆git存储库时,它工作正常,但在Jenkins中它没有使用配置文件进行端口.
我尝试过提供ssh URL,但它也无效."Connection refused" error来了.我尝试在管理Jenkins -> configure system page in SSH Server部分给出固定端口号.但仍然没有解决问题.
有没有办法我们可以配置项目使用Jenkins中的特定端口 - > Git或者可能访问.ssh/config文件来获取端口号?
我正在使用SSH密钥来访问git.