根据这篇有用的帖子,我删除了我的帖子~/.sbtconfig,并添加了.sbtopts:
$cd myProject
$cat .sbtopts
-J-Xmx4G
-J-XX:+CMSClassUnloadingEnabled
-J-XX:MaxPermSize=4G
Run Code Online (Sandbox Code Playgroud)
然后我跑了sbt.我如何通过sbt控制台验证设置的选项.sbtopts?
使用Idris类型驱动开发提供此程序:
StringOrInt : Bool -> Type
StringOrInt x = case x of
True => Int
False => String
Run Code Online (Sandbox Code Playgroud)
如何在Scala中编写这样的方法?
我在命令行上通过mvn构建我的项目.
每当发生checkStyle错误时,我都会看到这种类型的输出:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-checkstyle-
plugin:2.4:checkstyle (default) on project myProject-server:
An error has occurred in Checkstyle report generation.
There are 2 checkstyle errors. -> [Help 1]
Run Code Online (Sandbox Code Playgroud)
如何找出导致这些CheckStyle失败的代码行?
我的C#代码使用托管C++包装器.要创建这个Wrapper类型的新对象,我需要将String转换为Sbyte*.一些StackOverflow.com帖子讨论了如何将String转换为byte [],以及将byte []转换为sbyte [],而不是String转换为sbyte*.
msdn.social.com提供有关如何将字节数组转换为字符串的建议:
> // convert String to Sbyte*
> string str = "The quick brown, fox jumped over the gentleman.";
>
> System.Text.ASCIIEncoding encoding = new
> System.Text.ASCIIEncoding();
>
> Byte[] bytes = encoding.GetBytes(str);
Run Code Online (Sandbox Code Playgroud)
但是,"bytes"不是sbyte*类型.我以下尝试将字节转换为sbyte*失败:
Run Code Online (Sandbox Code Playgroud)1. Convert.ToSbyte(bytes); 2. cast: (sbyte*) bytes;
请告诉我如何将C#字符串转换为sbyte*.
另外,请谈谈介绍sbyte*的任何副作用,我认为这是不安全的代码.
谢谢,凯文
MSDN给出了这个深拷贝的例子(http://msdn.microsoft.com/en-us/library/system.object.memberwiseclone.aspx)
public class Person
{
public int Age;
public string Name;
public IdInfo IdInfo;
public Person ShallowCopy()
{
return (Person)this.MemberwiseClone();
}
public Person DeepCopy()
{
Person other = (Person) this.MemberwiseClone();
other.IdInfo = new IdInfo(this.IdInfo.IdNumber);
return other;
}
}
Run Code Online (Sandbox Code Playgroud)
但是,是否必须实例化一个新的Person对象,然后返回?例如,此代码是否可接受/等于/低于上述代码执行深层复制?
据我了解的是MemberwiseClone()方法,它只执行浅拷贝,即将复制对象的值/引用复制到新对象.由于内存引用相等,这导致浅拷贝,即引用指向相同的对象.
public class Person
{
public int Age;
public string Name;
public IdInfo IdInfo;
public Person ShallowCopy()
{
return (Person)this.MemberwiseClone();
}
public Person DeepCopy()
{
Person other = new Person(); // difference
other.IdInfo = new IdInfo(this.IdInfo.IdNumber);
return other;
} …Run Code Online (Sandbox Code Playgroud) Scaladocs解释了如何向Vector添加元素.
def :+(elem: A): Vector[A]
[use case] A copy of this vector with an element appended.
Run Code Online (Sandbox Code Playgroud)
例:
scala> Vector(1,2) :+ 3
res12: scala.collection.immutable.Vector[Int] = Vector(1, 2, 3)
Run Code Online (Sandbox Code Playgroud)
对于大型集合,复制整个Vector,然后向其添加元素似乎很昂贵.
将元素添加到Vector的最佳(最快)方法是什么?
Brent Yorgey的Typeclassopedia提供了以下练习:
举一个
* -> *不能成为Functor(不使用undefined)实例的类型的例子.
请告诉我" 不能成为实例Functor "的意思.
此外,我会欣赏一个例子,但也许作为一个扰流板,所以你可以,请指导我的答案.
我使用Jackson测试了Scala案例类的序列化.
DeserializeTest.java
public static void main(String[] args) throws Exception { // being lazy to catch-all
final ObjectMapper mapper = new ObjectMapper();
final ByteArrayOutputStream stream = new ByteArrayOutputStream();
mapper.writeValue(stream, p.Foo.personInstance());
System.out.println("result:" + stream.toString());
}
}
Run Code Online (Sandbox Code Playgroud)
Foo.scala
object Foo {
case class Person(name: String, age: Int, hobbies: Option[String])
val personInstance = Person("foo", 555, Some("things"))
val PERSON_JSON = """ { "name": "Foo", "age": 555 } """
}
Run Code Online (Sandbox Code Playgroud)
当我运行上面main的Java类时,抛出了一个异常:
[error] Exception in thread "main" org.codehaus.jackson.map.JsonMappingException:
No serializer found for class p.Foo$Person and …Run Code Online (Sandbox Code Playgroud) 为什么这种比较评估true?
scala> Double.NaN equals java.lang.Double.NaN
res5: Boolean = true
Run Code Online (Sandbox Code Playgroud)
但这一个评估到false?
scala> Double.NaN == java.lang.Double.NaN
res6: Boolean = false
Run Code Online (Sandbox Code Playgroud)
除此之外:这个有趣的Twitter帖子促使我提出这个问题
我在Redshift中创建了一个表:
create table myTable (
dateTime TIMESTAMP NOT NULL,
...
);
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试插入包含a dateTime的记录时,我收到错误stl_load_errors.
20080215 04:05:06.789
由于我从文档中获取了这个时间戳,我希望它能够起作用.
Redshift的错误日志显示:
时间戳格式或值无效[YYYY-MM-DD HH24:MI:SS]
但是,我想包括3秒,例如:2015-02-01 15:49:35.123.
如何修改我的时间戳字段以在几秒钟内以额外的精度插入它?