小编om-*_*nom的帖子

意外错误:重新分配给val

编译时出现此错误:

Compilation error: reassignment to val
Run Code Online (Sandbox Code Playgroud)

我认为这看起来很明显,但在查看我的代码时,我无法找到为什么这不起作用.

以下是我的ConferenceController.scala中发生错误的代码示例:

def createConfWithPrivacy(confId: Long, groupId: Option[Long]) = ForcedAuthentication 
{implicit request =>
    Future {
      val user = request.user.get
      var newConf = Conference.findById(confId).get
      if(groupId.isDefined){
        newConf.forGroup = LabGroup.findById(groupId.get)  <- there it is
        Conference.updateForGroup(newConf)
      }
      ...
    }
}
Run Code Online (Sandbox Code Playgroud)

Conference.scala中的变量声明如下:

case class Conference (
    id         : Long,
    title      : String,
    abstr      : String,
    speaker    : Speaker,
    startDate  : DateTime,
    length     : Duration,
    organizedBy: Lab,
    location   : Location,
    accepted   : Boolean,
    acceptCode : Option[String],
    priv       : Boolean,
    forGroup   : …
Run Code Online (Sandbox Code Playgroud)

scala

0
推荐指数
1
解决办法
3771
查看次数

为什么我在Scala-IDE中有"类型不匹配;找到单位,预期布尔"?

我有以下Scala代码(从Java端口移植):

import scala.util.control.Breaks._

object Main {

def pascal(col: Int, row: Int): Int = {
    if(col > row) throw new Exception("Coloumn out of bound");
    else if (col == 0 || col == row) 1;
    else pascal(col - 1, row - 1) + pascal(col, row - 1);
}
def balance(chars: List[Char]): Boolean = {
  val string: String = chars.toString()
  if (string.length() == 0) true;
  else if(stringContains(")", string) == false && stringContains("(", string) == false) true;
  else if(stringContains(")", string) ^ stringContains("(", string)) false; …
Run Code Online (Sandbox Code Playgroud)

scala scala-ide

-1
推荐指数
1
解决办法
2881
查看次数

"List <String> words = new ArrayList <String>();" 不要编译

我发布了一个关于如何从文件中读取并从该文件中返回一个随机单词的问题,每个人都在告诉我使用"List words = new ArrayList();" 我确实尝试使用它,它不起作用!

我已经尝试了一切!我是java的新手,因为我还是学生!所以互联网是我的最后选择,教科书是没用的...

我想要做的就是从该文件中返回一个随机字符串,然后将其用作猜测词

在此输入图像描述

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
import java.util.ArrayList;
import java.util.Random;
import java.util.*;

public final class Hangman extends JFrame implements ActionListener {
    int i = 0;
    static JPanel panel;
    static JPanel panel2;
    static JPanel panel3;
    static JPanel panel4;

    public Hangman() {
        JButton[] buttons = new JButton[26];

        panel = new JPanel(new GridLayout(0, 9));
        panel2 = new JPanel();
        panel3 = new JPanel();
        panel4 = new JPanel();

        JButton btnRestart = new JButton("Restart");
        btnRestart.addActionListener(new ActionListener() …
Run Code Online (Sandbox Code Playgroud)

java

-2
推荐指数
2
解决办法
2181
查看次数

Scala Value不是Unit的成员

我的代码有小问题,我在java及其工作中编写代码但由于某种原因它不能在Scala中工作.任何的想法 ?

def main(args: Array[String]) {

    val in = new Scanner(System.in)
    var T: String = null
    var P: String = null
    var cand: String = null
    var pos: Int = 0
    var i: Int = 0

    System.out.print("Enter a text string T: ")
    T = in.nextLine()
    System.out.print("Enter a pattern string P: ")
    P = in.next()
    println()
    pos = 0

    while (pos <= T.length - P.length) {
      cand = T.substring(pos, pos + P.length)
      if (P == cand) {
        println(T)
        i = 0 …
Run Code Online (Sandbox Code Playgroud)

scala

-4
推荐指数
1
解决办法
9609
查看次数

标签 统计

scala ×3

java ×1

scala-ide ×1