21 Matching Annotations
  1. Jan 2022
    1. enum can contain both concrete methods and abstract methods. If an enum class has an abstract method, then each instance of the enum class must implement it 

      Yet to explore abstract methods for java enums

    2. We can’t create enum objects explicitly and hence we can’t invoke enum constructor directly.

      Color c1 = Color.RED;

      Color is the enum and "RED" is internally a class object of class "Color".

      In which language though, can invoke the constructor directly? I guess by using the parameterized constructors, one can invoke other constructors easily.

    3. Since it is static, we can access it by using the enum Name. Since it is final, we can’t create child enums.

      enum in java is implemented as a class. The static and final keywords have their meanings.

      An enum cannot explicitly inherit a class not can it create child enums.

    4. enum can implement many interfaces

      Have to learn about Interfaces.

    5. All enums implicitly extend java.lang.Enum class. As a class can only extend one parent in Java, so an enum cannot extend anything else.

      In Java, a class can extend only one parent class. Also, an enum implicitly extends the java.lang.Enum class. Therefore, an enum cannot extend anything else.

    6. In Java, we can also add variables, methods and constructors to it

      java enums allow one to add variables, methods and constructors. Java enums are apparently more powerful than C++ enums

    7. enum type can be passed as an argument to switch statement.

      An enum object can be created and the object can be passed as an argument.

  2. Jun 2021
    1. It is a compile-time error if an enum declaration has the modifier abstract orfinal.

      enum is implicitly static and final, no reason to have modifiers final and abstract.

  3. Dec 2019
    1. Arguably, the rails-team's choice of raising ArgumentError instead of validation error is correct in the sense that we have full control over what options a user can select from a radio buttons group, or can select over a select field, so if a programmer happens to add a new radio button that has a typo for its value, then it is good to raise an error as it is an application error, and not a user error. However, for APIs, this will not work because we do not have any control anymore on what values get sent to the server.
    2. liberal_enum :kind
    1. When the controller creates the user, instead of adding a validation error to the record, it raises an exception. How to avoid this?
    2. I really dislike the reasoning as stated in the issue listed above. Since the value is coming over the wire, it should be treated the same as a freetext input where the expectation is to validate in the model and not the controller. This is especially true in APIs where the developers have even less of a say as far as expected input coming from form data (for example).
    3. In case anyone wants a hack, here is what I came up with.
  4. Nov 2019
  5. Oct 2019
    1. const renderMapping: { [l in letters]: renderFunction<l>; } = { 'a': (a: 'a') => 'alpha', 'b': (b: 'b') => 'bravo', }; type renderFunction<l extends letters> = (letter: l) => string; function renderLetter<l extends letters>(letter: l): renderFunction<l> { return renderMapping[letter]; }
  6. Aug 2019
  7. Mar 2018