加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

类片段和对象片段之间的区别

发布时间:2020-12-16 18:18:14 所属栏目:安全 来源:网络整理
导读:我想知道类片段和电梯中的对象片段之间的确切区别. 如果我有 class Foo { var a: String def render(n:NodeSeq) = { h3 you chose {a} /h3 }} 和 object Bar { var b: String def render(n:NodeSeq) = { h3 you chose {b} /h3 }} 它们之间的具体区别是什么,a
我想知道类片段和电梯中的对象片段之间的确切区别.

如果我有

class Foo {
  var a: String
  def render(n:NodeSeq) = {
    <h3> you chose {a} </h3>
  }
}

object Bar {
  var b: String
  def render(n:NodeSeq) = {
    <h3> you chose {b} </h3>
  }
}

它们之间的具体区别是什么,a和b有不同的行为.
在simply lift,据说

In this case,the snippet is an object singleton because it does not take any constructor parameters and has no instance variabled.

那对于每个用户来说,Bar会是一样的吗?

我知道这是一个noob问题,但是我需要非常清楚这一点,我不能很好地匹配片段中对象和类之间的区别.

解决方法

见 this page.

基本上,将为每个http请求创建一个新的Foo实例(因此会有许多同时存在),但只有一个Bar实例将同时存在.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读