我有一个Scala域类(用于持久化到数据库),如:
class Foo() {
var bar: Long = _ // or None or null ???
var jaz: String = _ // or None or null or empty string "" ???
}
如果字段bar和jaz是必填字段而不是可选字段,如何影响答案?
我想知道在Scala中调用类型参数化方法时是否可以使用默认类型.假设我在某处有以下方法:
def apply[A]( id: String )( implicit processor: Processor[A] ) =
  processor( data get id )
我想A是String,当编译器没有关于来推断哪种类型的提示.所以我可以重载我的定义:
def apply( id: String )( implicit processor: Processor[String] ) =
  processor( data get id )
但是这两种方法在擦除后都会有相同的签名...有没有办法提供默认类型?
我目前正在Eclipse中的Scala中编写一个项目,这是一个真正的麻烦,必须输入整个包名来进入我编写的类.例如:
如果我在com.ab.cd.ef.gh包中编写一个类Sender,那么每当我尝试使用该对象时,我必须执行以下操作:
val sender = com.ab.cd.ef.gh.Sender.getSender
或类似的东西.有没有办法设置解释器,所以我只需要输入
val sender = Sender.getSender
?
我开始知道使用Reflection我们可以在不使用"new"关键字的情况下创建对象.所以我想知道它们或使用Reflection的任何特定场景是否存在任何差异.因为到目前为止我没有创建或看到任何用反射创建对象的代码.
为什么使用'new'变得如此习惯和反思.
我正在尝试定义一个使用相应伴随对象的特征,即使用特征的类的componion对象.
例如,我有:
:paste
class Parent {
  def callMyCompanion = print(Parent.salute)
}
object Parent {
  def salute = "Hello from Parent companion object"
}
class Child extends Parent {
}
object Child {
  def salute = "Hello from Child companion object"
}
然后我创建一个父对象:
scala> val p = new Parent()
p: Parent = Parent@1ecf669
scala> p.callMyCompanion
Hello from Parent companion object
但是带着孩子:
scala> val c = new Child()
c: Child = Child@4fd986
scala> c.callMyCompanion
Hello from Parent companion object
我想得到:来自Child伴侣对象的Hello
我怎么能实现呢???
- …
我想知道,如何用单引号计算字符串的整数值' '.
我的示例代码是:
#include <stdio.h>
int main()
{
    int c = 'aA';
    int d = 'Aa';
    printf( "%d %d" , c, d);
    return 0;
}
输出是:
24897 16737
那些数字是多少?有没有计算它们的公式?
我正在阅读有关Akka和Camel集成的内容.我第一次穿过Camel,听起来很棒.我们可以明确地使用Akka和Camel构建REST服务吗?那个方向有什么有用的指针吗?
我最近读了几个声明的递归函数static.
static在函数声明前添加是否有助于GCC优化尾递归函数?这是否必须获得优化?
我想知道我是否可以调整以下Scala代码:
def removeDuplicates(listOfTuple: List[(Class1,Class2)]): List[(Class1,Class2)] = {
           var listNoDuplicates: List[(Class1, Class2)] = Nil
           for (outerIndex <- 0 until listOfTuple.size) {
             if (outerIndex != listOfTuple.size - 1)
               for (innerIndex <- outerIndex + 1 until listOfTuple.size) {
                 if (listOfTuple(i)._1.flag.equals(listOfTuple(j)._1.flag))
                   listNoDuplicates = listOfTuple(i) :: listNoDuplicates
               }
           }
           listNoDuplicates
         }
case class Message(xml : Node) {
  def toXML : Node = xml
}
case class ReqValidationMessage (xml : Node) extends Message(xml){
  // ...
}
当Scala尝试在ReqValidationMessage案例类中创建名为xml的第二个属性时,这会导致属性命名冲突.但我希望两个构造函数(Message和ReqValidationMessage)具有相同的论证.我该怎么办?
我有一个Java String对象,其值为:"c:SAMPLE".它的offset = 2和count = 6,所以实际的字符串是"SAMPLE".
如何构建一个等于"c:SAMPLE"的新String?
以下是公式
脂肪百分比= 495 /(1.0324 - 0.19077 x(LOG10(腰围))+ 0.15456 x(LOG10(身高))) - 450
以下是我的代码
import java.math.*;
public class Position
{
    static double waist=66,neck=30,height=150;
    public static void main(String[]args)
    {
        double fat = 495 / ( (1.0324 - 0.19077)* (Math.log(waist - neck)/Math.log(10)) + (0.15456) *  (Math.log(height)/Math.log(10))) - 450;
        System.out.println(fat);
    }
}
我得到的答案是错误的.它应该是11.8%(使用以下http://lowcarbdiets.about.com/library/blbodyfatcalculator.htm)
我相信我在对数方面做错了.请帮助我得到正确的答案.
scala ×8
java ×3
c ×2
inheritance ×2
actor ×1
akka ×1
apache-camel ×1
ascii ×1
case-class ×1
eclipse ×1
gcc ×1
generics ×1
math ×1
recursion ×1
reflection ×1
rest ×1
static ×1
string ×1
traits ×1
types ×1