Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6634467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:55:59+00:00 2026-05-25T22:55:59+00:00

I have the following class definition in Scala: class AppendErrorMessageCommand private(var m_type: Byte) {

  • 0

I have the following class definition in Scala:

class AppendErrorMessageCommand private(var m_type: Byte) {

  def this() = this(0x00)

  def this(errorType: ErrorType) = this(getErrorTypeValue(errorType))

  private def getErrorTypeValue(errorType: ErrorType) = {
    if(errorType == USER_OFFLINE)
      0x01
    else if(errorType == PM_TO_SELF)
      0x02

    0x00  
  }
}

ErrorType is the following enum:

object ErrorType extends Enumeration {

  type ErrorType = Value
  val USER_OFFLINE, PM_TO_SELF = Value
}

I think something is wrong with the constructor definitions in the class. My IDE (which is the Scala IDE for Eclipse) tells me it cannot find getErrorTypeValue. It also tells me that the overloaded constructor is has alternatives. One being the byte and the other the enum.

Don’t take these error messages of the IDE seriously though. They might be wrong, as this often happens with the IDE. But nonetheless, when the IDE tells me something is wrong, it usually is wrong.

So, what is the problem with my class/constructor definitions?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T22:56:00+00:00Added an answer on May 25, 2026 at 10:56 pm

    In this case the IDE is perfectly correct and agrees with the scala command line compiler.

    Your constructor takes a Byte, so you need to provide it with one (0x00 is an Int), you need to import ErrorType._ and you need to move getErrorTypeValue to the companion object and declare it to return a Byte (the inferred type is an Int):

    object ErrorType extends Enumeration {
      type ErrorType = Value
      val USER_OFFLINE, PM_TO_SELF = Value
    }
    
    import ErrorType._
    
    object AppendErrorMessageCommand {
      private def getErrorTypeValue(errorType: ErrorType): Byte = {
        if(errorType == USER_OFFLINE)
          0x01
        else if(errorType == PM_TO_SELF)
          0x02
    
        0x00  
      }
    }
    
    class AppendErrorMessageCommand private(var m_type: Byte) {
      def this() = this(0x00.toByte)
      def this(errorType: ErrorType) = this(AppendErrorMessageCommand.getErrorTypeValue(errorType))
    }
    

    Another, better way is to avoid having multiple constructors and use a factory method:

    object AppendErrorMessageCommand {
      def apply() = new AppendErrorMessageCommand(0x00)
      def apply(b: Byte) = new AppendErrorMessageCommand(b)
      def apply(errorType: ErrorType) = new AppendErrorMessageCommand(AppendErrorMessageCommand.getErrorTypeValue(errorType))
    
      private def getErrorTypeValue(errorType: ErrorType): Byte = {
        if(errorType == USER_OFFLINE)
          0x01
        else if(errorType == PM_TO_SELF)
          0x02
    
        0x00  
      }
    }
    
    class AppendErrorMessageCommand private(var m_type: Byte) {
    }
    

    See the answers to How can I call a method in auxiliary constructor?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's have the following class definition: CThread::CThread () { this->hThread = NULL; this->hThreadId =
I have the following Bird definition: class Bird: def __init__(self, swarm, position = None):
I have the following class definition: template<typename QueueItemT> class QueueBC { protected: QueueBC() {}
I have a the following method definition in my class: virtual Calc* Compile( Evaluator*
I have following class public class ButtonChange { private int _buttonState; public void SetButtonState(int
I have the following class definition. Contact.h #import <CoreData/CoreData.h> @interface Contact : NSManagedObject {
I have the following (cut-down) class definition, and it has compilation errors. #include <iostream>
I have the following abstract classes: public abstract class AbSuperClass1<K,S> { //class definition }
I have the following VB.NET class definition: <Serializable()> Partial Public Class Customers End Class
Suppose I have a class with following definition: class ClassA { static belongsTo =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.