fork download
  1. object Main extends App {
  2.  
  3. abstract class Table[T] {
  4. def schema
  5. }
  6.  
  7. class TableSchema[T]
  8.  
  9. case class Person(id: Option[Int], fname: String, lname: String, nonDbValue: String)
  10.  
  11. class AutoSchemeTable[C <: TableSchema[T], T](tblSchema: C) extends Table[T] {
  12.  
  13. def getScheme = ??? // читаем в рантайме поля С и T и формируем схему
  14.  
  15. def schema = getScheme
  16. }
  17.  
  18. class PersonTable extends TableSchema[Person] {
  19. val nonDBValue = "cherv-pidor"
  20. }
  21.  
  22. val personTable = new AutoSchemeTable[PersonTable, Person](new PersonTable)
  23. val personTable2 = new AutoSchemeTable(new PersonTable)
  24.  
  25.  
  26. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
/opt/scala/bin/scalac: line 50: /dev/null: Permission denied
Main.scala:23: error: inferred type arguments [Main.PersonTable,Nothing] do not conform to class AutoSchemeTable's type parameter bounds [C <: Main.TableSchema[T],T]
	val personTable2 = new AutoSchemeTable(new PersonTable)
                           ^
Main.scala:23: error: type mismatch;
 found   : Main.PersonTable
 required: C
	val personTable2 = new AutoSchemeTable(new PersonTable)
                                               ^
two errors found
spoj: The program compiled successfully, but Main.class was not found.
      Class Main should contain method: def main(args: Array[String]).
stdout
Standard output is empty