Last active
November 6, 2017 16:56
-
-
Save t0mmyt/ef7d090cd9c1e53e2f8a to your computer and use it in GitHub Desktop.
Scala Code Smells
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val this_instruction = "sml." + fields(1).capitalize + "Instruction" | |
val instruction_args = fields.drop(2) | |
val c_int = classOf[Int] | |
val c_str = classOf[String] | |
val instruction = instruction_args.length match { | |
case 1 => | |
val c = Class.forName(this_instruction).getConstructor(c_str, c_str, c_int) | |
c.newInstance(fields(0), fields(1), fields(2).toInt: Integer).asInstanceOf[Instruction] | |
case 2 => | |
val c = Class.forName(this_instruction).getConstructor(c_str, c_str, c_int, c_int) | |
c.newInstance(fields(0), fields(1), fields(2).toInt: Integer, fields(3).toInt: Integer).asInstanceOf[Instruction] | |
case 3 => | |
val c = Class.forName(this_instruction).getConstructor(c_str, c_str, c_int, c_int, c_int) | |
c.newInstance(fields(0), fields(1), fields(2).toInt: Integer, fields(3).toInt: Integer, fields(4).toInt: Integer).asInstanceOf[Instruction] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Very elegant solution :) typesafety? What?! Reflection? WHAT?! Matching instruction args instead of it's length?! Come on! Are you kidding...