在Scala中对象是单身......所以如果我做:
trait SimpleTrait {
def setString(s: String): Unit = {
InnerTraitObject setString s
}
def getString(): String = {
return InnerTraitObject getString
}
object InnerTraitObject {
var str: String = ""
def setString(s: String): Unit = {
str = s
}
def getString(): String = {
return str
}
}
}
Run Code Online (Sandbox Code Playgroud)
然后
class SimpleClass extends SimpleTrait{
/// empty impl
}
Run Code Online (Sandbox Code Playgroud)
和:
object App {
def main(args: Array[String]): Unit = {
val a = new SimpleClass();
val b = new SimpleClass(); …
Run Code Online (Sandbox Code Playgroud) 我对使用Java 8中的新流API的代码设计没有什么问题.我想学习新的东西,其中一个任务是:
从列表中拒绝最大值和最小值.列表不包含重复项.
看起来很简单 不...我的代码:
List<Integer> ranges = Lists.newArrayList(new Range(1, 15));
List<Integer> collect = ranges.stream()
.filter(x -> x != ranges.stream()
.mapToInt(Integer::intValue)
.max()
.getAsInt())
.filter(x -> x != ranges.stream()
.mapToInt(Integer::intValue)
.min()
.getAsInt())
.collect(Collectors.toList());
assertThat(collect).hasSize(13); // OK
assertThat(collect).isEqualTo(Lists.newArrayList(new Range(2,14))); // OK
Run Code Online (Sandbox Code Playgroud)
这段代码很好(如果我们没有最小/最大的重复,但这不是一个核心问题)但问题是我在这里使用三个流.首先是主流,第二个是删除最大值,第三个是删除最小值.是否有可能在一个流中执行此任务?
//编辑:非常原始的Scala版本:
val list = List.range(1, 15).sortWith(_>_).tail.reverse.tail
Run Code Online (Sandbox Code Playgroud)
另外一种,因为我们可以有shuiffeled列表.
我有一些类(实体),其中的方法由@ PostLoad,@ PrePersist等注释,类有@EntityListeners注释.我想在我的测试环境中禁用回调方法和监听器的处理.
删除部分代码是不可能的,因为测试是在CI服务器上运行的,我没有任何可能只为测试更改代码.
是否有可能在JPA 2配置中关闭回调方法和实体侦听器?我使用Hibernate.
我正在尝试将示例响应值添加到我的 springdoc-openapi swagger 文档中。
比如用“马克·吐温”替换“字符串”等。
我尝试使用此解决方案 - springdoc-openapi: How to add example of POST request?
我已经org.springframework.web.bind.annotation.RequestBody
在我的课堂上使用了。
如果我用这个 -
@io.swagger.v3.oas.annotations.parameters.RequestBody(content = @Content(examples = {
@ExampleObject(
name = "Person sample",
summary = "person example",
value =
"{\"email\": test@gmail.Com,"
+ "\"firstName\": \"josh\","
+ "\"lastName\": \"spring...\""
+ "}")
}))
Run Code Online (Sandbox Code Playgroud)
我得到以下解释 -
no viable alternative at input ',@io.swagger.v3.oas.annotations.parameters.RequestBody(content=@Content(examples={@ExampleObject(name="Person sample",summary="person example",value="{\"email\": test@gmail.Com,"+"\"firstName\": \"josh\","+"\"lastName\": \"spring...\""+"}")})))': NoViableAltException```
Can anyone give me a solution please?
Run Code Online (Sandbox Code Playgroud) 我想在我们公司的git上构建特定的流程.
换句话说 - 是否可以在公共存储库中配置私有远程分支?
在 Ubuntu 16.04 上安装 OpenShift 后,我尝试运行它并得到如下错误:
koziolek@koziolek-desktop ~ $ oc cluster up
Getting a Docker client ...
Checking if image openshift/origin-control-plane:v3.11 is available ...
Pulling image openshift/origin-control-plane:v3.11
E0116 20:25:45.193436 29023 helper.go:179] Reading docker config from /home/koziolek/.docker/config.json failed: open /home/koziolek/.docker/config.json: no such file or directory, will attempt to pull image d
ocker.io/openshift/origin-control-plane:v3.11 anonymously
Pulled 1/5 layers, 21% complete
Pulled 2/5 layers, 58% complete
Pulled 3/5 layers, 64% complete
Pulled 3/5 layers, 76% complete
Pulled 3/5 layers, 91% complete
Pulled 4/5 layers, …
Run Code Online (Sandbox Code Playgroud) 类似的问题: JDBC的奇怪问题,选择返回null 但人们没有要求这个.
我的代码:
public int myMethod(String day) throws SQLException{
String sql = "Select count(*) from MyTable WHERE someColumn = " + day;
Connection connection = ConnFactory.get();
PreparedStatement prepareStatement = null;
ResultSet resultSet = null;
int ret = -1;
try{
prepareStatement = connection.prepareStatement(sql);
resultSet = prepareStatement.executeQuery(sql);
if(resultSet.next()){
ret = resultSet.getInt(1);
}
}
catch(SQLException sqle){
// closing statement & ResultSet, log and throw exception
}
finally{
// closing statement & ResultSet
}
ConnFactory.kill(connection);
return ret;
}
Run Code Online (Sandbox Code Playgroud)
此代码始终返回0.我尝试在执行前记录sql并尝试在SQLdeveloper中运行它并获得正确的值(超过100).当我删除WHERE时,sql = "Select count(*) …
首先,我有特点:
import _root_.com.thoughtworks.selenium._
import org.scalatest.matchers.ShouldMatchers
import org.scalatest.matchers.ShouldMatchers._
trait SeleniumField extends ShouldMatchers {
val name : String
def selenium : Selenium
def text : String = { return selenium.getValue(name) }
def is(v:String) : Boolean = { this.value equals v }
def set(v:String) = { selenium.`type`( name , v ) }
}
Run Code Online (Sandbox Code Playgroud)
然后我用这个特性创建scala类:
import _root_.com.thoughtworks.selenium._
class WebAppField(sel:Selenium, nam: String) extends SeleniumField {
def selenium = sel
override val name = nam
}
Run Code Online (Sandbox Code Playgroud)
然后当我尝试在代码中使用它时:
val rodzaj = new WebAppField(selenium, "RODZAJ")
rodzaj text should …
Run Code Online (Sandbox Code Playgroud) 我使用Scala 2.9.1.我有一个简单的scala"解释器":
import scala.tools.nsc.interpreter.IMain
import scala.tools.nsc.interpreter.Results.Result
import scala.tools.nsc.interpreter.Results.Success
object App {
def main(args: Array[String]) {
val interpreter = new IMain
val result:Result = interpreter.interpret(args(0))
result.toString() match {
case "Success" =>
{
var success = result.asInstanceOf[Success]
println(success.productElement(0))
};
case _ => println("very bad result");
}
}
}
Run Code Online (Sandbox Code Playgroud)
当我尝试编译它(maven)时,我得到:
[ERROR] /home/koziolek/workspace/dsi/src/main/scala/pl/koziolekweb/scala/dsi/App.scala:15: error: not found: type Success
[INFO] var success = result.asInstanceOf[Success]
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,编译器表示没有类型Success,尽管我导入了它.
我在java中的日期转换有一点问题.当我把19700101放到SimpleDateFormat然后调用getTime时我得到-3600000.我写测试:
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
Date date = dateFormat.parse("19700101");
System.out.println(date.getTime());
System.out.println(dateFormat.format(new Date(0)));
System.out.println((new Date(0)).getTime());
Run Code Online (Sandbox Code Playgroud)
结果应该是:
0
19700101
0
Run Code Online (Sandbox Code Playgroud)
但我得到了
-3600000
19700101
0
Run Code Online (Sandbox Code Playgroud)
我的问题是为什么SimpleDateFormat返回-3600000(20Nov1969)?我在哪里可以找到有关格式化和转换错误的信息?
java ×5
scala ×3
collections ×1
docker ×1
git ×1
git-branch ×1
hibernate ×1
interpreter ×1
java-8 ×1
java-stream ×1
jdbc ×1
jpa-2.0 ×1
openapi ×1
openshift ×1
oracle10g ×1
scala-2.8 ×1
scope ×1
singleton ×1
spring-boot ×1
sql ×1
swagger ×1
testing ×1