task scalaTest(dependsOn: testClasses) << {
description = 'Runs Scalatest suite'
ant.taskdef(name: 'scalatest',
classname: 'org.scalatest.tools.ScalaTestAntTask',
classpath: sourceSets.test.runtimeClasspath.asPath
)
ant.scalatest(runpath: sourceSets.test.output.classesDir,
haltonfailure: 'true', fork: 'false') {
reporter(type: 'stdout')
}
}
Run Code Online (Sandbox Code Playgroud)
我跑了gradle scalaTest,我得到:
* What went wrong:
Execution failed for task ':scalaTest'.
> java.lang.NoClassDefFoundError: scala/reflect/ClassManifest$
Run Code Online (Sandbox Code Playgroud)
我正在使用Scala 2.10.2和Gradle 1.7
dependencies {
compile 'org.scala-lang:scala-library:2.10.2'
testCompile 'org.scalatest:scalatest:1.3'
testCompile 'org.scalamock:scalamock_2.10:3.0.1'
}
Run Code Online (Sandbox Code Playgroud)
怎么了??
是否安全:
public class Widget {
private static final IllegalStateException LE_EXCEPTION
= new IllegalStateException("le sophisticated way");
...
public void fun() {
// some logic here, that may throw
throw LE_EXCEPTION;
}
....
}
Run Code Online (Sandbox Code Playgroud)
而不是new每次都抛出异常?
我感兴趣的是它是否安全
安全我的意思是:没有内存损坏,没有JVM抛出的额外异常,缺少类,没有加载坏类(...).注意:异常将通过网络抛出(远程处理).
其他问题(可读性,保持实例的成本)并不重要.
我用这种方式在JSP中显示字符串:
${someString}
Run Code Online (Sandbox Code Playgroud)
当然,这个字符串可能包含特殊的html字符.目前可以HTML注入恶意代码(例如,如果someString是javascript包含 - <script src...>).
如何在打印前确保所有字符串都被转义?
我正在使用Spring MVC和JSP.
是否可以在Hibernate中为嵌入类的成员定义唯一约束?
我需要确保Nested :: i1和Nested :: i2作为一对(组合)是唯一的
@Entity
@Table( uniqueConstrains = ???)
public class Widget {
@Id
private int id;
@Embedded
Nested nested;
}
@Embeddable
public class Nested {
private int i1;
private int i2;
}
Run Code Online (Sandbox Code Playgroud) 我有关键字和运算符的枚举(以及其他一些),例如(都是相似的):
object Keywords extends Enumeration {
val AND, ARRAY, BEGIN, ...= Value
case class Keyword(keyword: Value) extends Token[Value] {
def this(keyword: String) = this(Keywords.fromString(keyword))
def value = keyword
}
implicit def valueToKeyword(keyword: Value) = new Keyword(keyword)
}
Run Code Online (Sandbox Code Playgroud)
这种隐式转换允许我传递枚举值,其中Tokens是预期的,例如
def testFunction[T](t: Token[T]) = ...
testFunction(Keywords.ARRAY) // gets converted
testFunction(Operators.PLUS) // gets converted too
Run Code Online (Sandbox Code Playgroud)
似乎在匹配期间也没有应用相同的隐式转换
val token = new Keyword("ARRAY")
token match {
case Keywords.ARRAY => ... // not selected but SHOULD be
case Operators.PLUS => ... // completely different …Run Code Online (Sandbox Code Playgroud) 我将我的JavaScript代码分成几个文件,全部使用模块模式(更新一个全局变量,比如说MyApp,具有新功能和成员).
是否可以将文件缩小为一个而不会破坏范围
示例我想缩小:
File1.js
var Module = (function(ns) {
ns.fun1 = function() { alert('fun1'); };
return ns;
})(Module || {});
Run Code Online (Sandbox Code Playgroud)
File2.js
var Module = (function(ns) {
ns.fun2 = function() { alert('fun2'); };
return ns;
})(Module || {});
Run Code Online (Sandbox Code Playgroud) 如果我有一个带有公共成员的模块,我会像这样使用它
Module.Sub.member()
Run Code Online (Sandbox Code Playgroud)
然后,将成员静态导入到本地范围(如usingcpp或import staticJava中)的最佳方法(如果存在)是什么?
我对枚举类(VS2012)的使用:
class matrix {
public:
enum class operation_type {ADD, MULT};
matrix(operation_type op);
...
}
Run Code Online (Sandbox Code Playgroud)
在我使用的另一个片段中
matrix* m = new matrix(matrix::operation_type::ADD);
Run Code Online (Sandbox Code Playgroud)
如果名字很长,这就变得非常混乱.
有可能以某种方式导入枚举值,以便我可以写:
matrix* m = new matrix(ADD);
Run Code Online (Sandbox Code Playgroud)
嵌套类也一样 - 我可以导入它们吗?
Doxygen 文档应该放在包含防护之前还是之后?在名称空间之前或内部?
假设标头包含单个类 ( ) 的声明context,这就是我在这里记录的内容。
#ifndef CONTEXT_HPP
#define CONTEXT_HPP
#include <string>
/**
* The application context interface.
*/
namespace test {
class context { ... };
}
Run Code Online (Sandbox Code Playgroud) 一个非常简单的C程序:
#include <stdio.h>
#include <stdlib.h>
void process(int array[static 5]){
int i;
for(i=0; i<5; i++)
printf("%d ", array[i]);
printf("\n");
}
int main(){
process((int[]){1,2,3});
process(NULL);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我编译它: gcc -std=c99 -Wall -o demo demo.c
它确实编译,当我运行它时,它崩溃(非常可预测).
为什么?static数组参数中关键字的用途是什么(这个构造的名称是什么btw?)?
int eye[3][3] = {
{ 1,0,0 },
{ 0,1,0 },
{ 0,0,1 }
};
Run Code Online (Sandbox Code Playgroud)
是否有更短的方式来初始化它?它是如此规则,必须有一个更聪明的方式来初始化它,特别是如果它超过3x3,比如10x10或更多.
有时我的文件看起来像这样:
using std::cout;
using std::endl;
using std::string;
using std::vector;
using std::size_type;
Run Code Online (Sandbox Code Playgroud)
是否有可能以某种方式避免每次都写出公共部分?像这样的东西:
USING(std, cout, endl, string, vector, size_type);
Run Code Online (Sandbox Code Playgroud)
我在考虑一个var-arg宏,但不知道是否有可能迭代那些var args.
int x = 1;
Consumer<Object> f = (i) -> {
int x = 1; // invalid
};
Run Code Online (Sandbox Code Playgroud)
与
Consumer<Object> f = (i) -> {
int x = 1;
};
int x = 1; // valid
Run Code Online (Sandbox Code Playgroud)
想象一下方法中的那两个块.为什么第二个块有效?