做强类型,在这种情况下char防止缓冲区溢出?
char a[100]
char b[100]
strcpy(a,unknownFunction); // unknownFunction could overflow b
// since its length is unknown
strcpy(b,a); // can b still overflow a with its now,
// potentially overflowed size?
Run Code Online (Sandbox Code Playgroud) 我发现这个Hibernate Criteria/Projection 教程清晰,简洁,内容丰富.
作者APRajshekhar说,
SELECT COUNT(ID) FROM ORDER HAVING PRICETOTAL>2000 GROUP BY ID
Run Code Online (Sandbox Code Playgroud)
可以在Criteria查询中重写如下:
List orders = session.createCriteria(Order.class)
.setProjection( Projections.projectionList()
.add( Projections.count(“id”) )
.add( Projections.groupProperty(“id”) )
)
.list();
Run Code Online (Sandbox Code Playgroud)
但是,在HAVING PRICETOTAL>2000Hibernate代码中出现的位置是什么?此比较是否存在缺少的标准(SQL中的where子句)?
Hibernate Docs(2.2.5.1.一对一)提供了以下示例:
@Entity
public class Customer implements Serializable {
@OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name="passport_fk")
public Passport getPassport() {
...
}
@Entity
public class Passport implements Serializable {
@OneToOne(mappedBy = "passport")
public Customer getOwner() {
...
}
Run Code Online (Sandbox Code Playgroud)
据我了解,Customer有一个一比一的关系Passport,这里Customer是所有者,即负责级联更新Passport.在mappedBy在Passport表明它有一个一对一的关系Customer,但它是不负责级联更新Customer.
Customer有一个外键约束Passport的,以及反之亦然Passport来Customer.
是什么意思@JoinColumn(name="passport_fk")的Customer?如何passport在mappedBy的Passport?它们是表示各自外键的表列吗?
Play的JSON 库包括:Functor和Invariant Functor:
我以前见过Functor:
trait Functor[M[_]] extends Variant[M] {
def fmap[A, B](m: M[A], f: A => B): M[B]
}
Run Code Online (Sandbox Code Playgroud)
但是,从概念上讲,它为什么需要提供这两种功能f1,并f2为InvariantFunctor?
trait InvariantFunctor[M[_]] extends Variant[M] {
def inmap[A, B](m: M[A], f1: A => B, f2: B => A): M[B]
}
Run Code Online (Sandbox Code Playgroud) 给出以下类型:
import Data.Set as Set
-- http://json.org/
type Key = String
data Json = JObject Key (Set JValue)
| JArray JArr
deriving Show
data JObj = JObj Key JValue
deriving Show
data JArr = Arr [JValue] deriving Show
data Null = Null deriving Show
data JValue = Num Double
| S String
| B Bool
| J JObj
| Array JArr
| N Null
deriving Show
Run Code Online (Sandbox Code Playgroud)
我JObject Key (Set Value)用一个元素创建了一个:
ghci> JObject "foo" (Set.singleton (B True))
JObject "foo" …Run Code Online (Sandbox Code Playgroud) 对于List,为什么right apply (*>)表现为重复并附加第二个参数n次数,n第一个参数的长度在哪里?
ghci> [1,2,3] *> [4,5]
[4,5,4,5,4,5]
Run Code Online (Sandbox Code Playgroud) 鉴于lazy val:
scala> lazy val y = {println("Y!"); 200}
y: Int = <lazy>
Run Code Online (Sandbox Code Playgroud)
我试图y进入Stream- 以确定是否会急切或懒惰地评估.
scala> Stream(100, y)
Y!
res4: scala.collection.immutable.Stream[Int] = Stream(100, ?)
Run Code Online (Sandbox Code Playgroud)
显然,它受到了热切的评价.
除了以下内容,我如何创建一个Stream懒惰的评估其成员?
scala> Stream[() => Int](() => 100, () => 200)
res18: scala.collection.immutable.Stream[() => Int] = Stream(<function0>, ?)
scala> res18.map(_())
res19: scala.collection.immutable.Stream[Int] = Stream(100, ?)
scala> res19.last
res20: Int = 200
scala> res19
res21: scala.collection.immutable.Stream[Int] = Stream(100, 200)
Run Code Online (Sandbox Code Playgroud) 给出以下代码:
Prelude> let f x = if (x) then 55 else "foo"
Run Code Online (Sandbox Code Playgroud)
为什么编译器会寻找Num [Char]?
<interactive>:2:23:
No instance for (Num [Char]) arising from the literal `55'
In the expression: 55
In the expression: if (x) then 55 else "foo"
In an equation for `f': f x = if (x) then 55 else "foo"
Run Code Online (Sandbox Code Playgroud)
但是,在Scala中,它将找到55and 的最小上限"foo",即Any:
scala> def f(x: Boolean) = if (x) 55 else "foo"
f: (x: Boolean)Any
import scala.reflect.runtime.universe._
scala> lub( List[Type]( …Run Code Online (Sandbox Code Playgroud) 根据 scala 规范, scala.Nothing 类型 - 所有类型的按钮。类型“Nothing”存在,但 Nothing 的实例不存在。
这个怎么运作:
def ??? : Nothing = throw new NoImplementedError
def sys.error(message: String): Nothing = throw new RuntimeException()
def sys.exit(status: Int): Nothing = {...}
Run Code Online (Sandbox Code Playgroud)
但实际上,所有提到的方法都返回异常。例外def sys.exit你能否澄清更多关于无类型的信息。任何例子,解释。
谢谢!
看看Travis Brown关于Type类和泛型派生的优秀博客文章,我看到以下方法:
implicit def hconsParser[H: Parser, T <: HList: Parser]: Parser[H :: T] =
new Parser[H :: T] {
def apply(s: String): Option[H :: T] = s.split(",").toList match {
case cell +: rest => for {
head <- implicitly[Parser[H]].apply(cell)
tail <- implicitly[Parser[T]].apply(rest.mkString(","))
} yield head :: tail
}
}
Run Code Online (Sandbox Code Playgroud)
什么意思H :: T的Parser[H :: T]?
另外,这case cell +: rest是如何处理s输入apply为空的情况?