首页 \ 问答 \ 下面的java代码在scala中的等效log4j语句是什么?(What is the equivalent log4j statement in scala for the below java code)

下面的java代码在scala中的等效log4j语句是什么?(What is the equivalent log4j statement in scala for the below java code)

我正在尝试在scala中使用log4j。 我的log4j文件也正确放置在资源目录中。

我遵循java中遵循的相同log4j方法

我的Java代码:这工作正常。 没有问题

package pack1;
import org.apache.log4j.Logger;

public class SampleMain {
final static Logger logger = Logger.getLogger(SampleMain.class);

public static void main(String[] args) {
    SampleMain lld = new SampleMain();
    lld.log();
}


public void log() {
    logger.fatal("This is fatal.");
    logger.error("This is error.");
    logger.warn("This is warn.");
    logger.info("This is info.");
    logger.debug("This is debug.");
    logger.trace("This is trace.");
  }


}

我的Scala代码:

import org.apache.log4j.Logger;


class SampleScala {

   val logger = Logger.getLogger(SampleScala.class)//getting compile time error at this line .  

  def method1():Unit = {

  }

}
object ScalaLogging {

def main(args: Array[String]): Unit = {

val obj = new SampleScala();
obj.method1()

 }
}

编译时间上面的scala错误代码:

 identifier expected but 'class' found.

所以我想知道下面的java代码的等效scala语句是什么

  final static Logger logger = Logger.getLogger(SampleMain.class); 

I am trying to use log4j in scala . I have log4j file properly placed inside resources directory as well.

I am following the same log4j approach which has been followed in java

My Java Code : This Works fine. No issues at all

package pack1;
import org.apache.log4j.Logger;

public class SampleMain {
final static Logger logger = Logger.getLogger(SampleMain.class);

public static void main(String[] args) {
    SampleMain lld = new SampleMain();
    lld.log();
}


public void log() {
    logger.fatal("This is fatal.");
    logger.error("This is error.");
    logger.warn("This is warn.");
    logger.info("This is info.");
    logger.debug("This is debug.");
    logger.trace("This is trace.");
  }


}

My Scala Code :

import org.apache.log4j.Logger;


class SampleScala {

   val logger = Logger.getLogger(SampleScala.class)//getting compile time error at this line .  

  def method1():Unit = {

  }

}
object ScalaLogging {

def main(args: Array[String]): Unit = {

val obj = new SampleScala();
obj.method1()

 }
}

Compile time Error in above scala Code :

 identifier expected but 'class' found.

So I would like to know what is the equivalent scala statement for the below java code

  final static Logger logger = Logger.getLogger(SampleMain.class); 

原文:https://stackoverflow.com/questions/42390445
更新时间:2021-10-28 19:10

最满意答案

正如Izzy主要说的那样,这不是一种常见的工作方式。 并且违背列表工作的方式可能会导致问题。 如果你想减少你的问题,把你的单元格的内容保存在内存中,并在willDisplayCell被调用时使用这个保存的内容来重新填充单元格,而不是从每次开始重建整个事物。


As Chiefly Izzy said, it's not a common way to work. And going against the way the lists work may cause problems. If you want to reduce your problem, keep the content of your cell in memory and use this saved content to refill the cell when willDisplayCell is called instead of rebuilding the whole thing from start each time.

相关问答

更多
  • 首先,让我们看看Message recycle()方法是如何工作的。 public void recycle() { if (isInUse()) { if (gCheckRecycle) { throw new IllegalStateException("This message cannot be recycled because it " + "is still in use."); } ...
  • 它会增加内存使用并影响滚动性能。 如果你只有10个电池,它可能没有任何区别。 有了1,000个,这将非常明显。 你还需要注释掉对tableView的出队调用。 但我必须问,为什么你关心这个问题? 您的问题可能有更好的解决方案。 根据您的评论,您可能仍然希望每行重复使用一个单元格,否则当某些内容从屏幕上滚动并返回时,您将不得不重新创建它。 您可以将indexPath行和部分合并到单元重用字符串中以实现此目的: NSString *cellIdentifier = [NSString stringWithFor ...
  • 在参数中使用FragmentManager而不是FragmentTransaction : @Override public void onClick(View v) { DialogFragment newFragment = new DatePickerDialogFragment(ChartingFragment.this); newFragment.show(getFragmentManager(), "date_picker_fialog"); } FragmentTransac ...
  • 正如Izzy主要说的那样,这不是一种常见的工作方式。 并且违背列表工作的方式可能会导致问题。 如果你想减少你的问题,把你的单元格的内容保存在内存中,并在willDisplayCell被调用时使用这个保存的内容来重新填充单元格,而不是从每次开始重建整个事物。 As Chiefly Izzy said, it's not a common way to work. And going against the way the lists work may cause problems. If you want t ...
  • 一旦你回收它就不能使用位图,所以在你回收它之后清除它的指针并在你绘制它之前检查它是否为null 如果为null,则再次加载它 you can't use a bitmap once you recycle it so clear the pointer to it after you recycle it and check that it isn't null before you draw it if it is null then load it again
  • 没弄错你。 但试试这个。 - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { [cell setBackgroundColor:[UIColor clearColor]]; } I could manage myself with the help of @Pankaj's answer ...
  • 听起来好像正在重复使用细胞。 单元重用的想法是当UITableViewCell的实例UITableViewCell屏幕时,在另一端需要新单元时再次使用该确切实例。 你正在一个单元格中启动一个计时器,该单元格被重用,并且因为它是同一个对象,它具有相同的计时器,它已经在运行。 如果您设计具有某种状态的单元格(例如,正在运行的计时器),则需要在单元格重用时重置该状态,否则它将保持不变。 如果您要在单元格中保留计时器,则需要安排在重复使用单元格时停止并重新启动计时器。 您可以通过覆盖表格单元类中的prepareFo ...
  • 我完全同意JAL ,你需要检查你所有的细胞结构,但我也知道有时候,在某些情况下,重构是不可能的。 所以,我想这个,假设你有一个由两个视图组成的CustomTableViewCell ,例如view1和view2命名: 代码: class MyView1 : UIView { var isTouched : Bool = false override func touchesBegan(touches: Set, withEvent event: UIEvent?) { ...
  • 一种可能的方案: - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; NSInteger row = [indexPath row]; UITableViewCell *cell = nil; if( row != kMapCellRow ) { // ...
  • 最好的办法是不要通过删除/添加来移动您的控件。 但要把它放在一个静态的细胞中。 这可以很容易地实现。 只需声明你的细胞: UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:... reuseIdentifier:nil self.segmentedControl.frame = CGRectMake(10, 10, cell.frame.size.width - 20, 30); self.segmentedControl.sele ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。