score:2
i was advised on this question. in such a situation the best approach is to use structural typing:
trait grand[t <: {def cloneobject: t}]
so that the user code might be the following:
case class person(name: string) {
def cloneobject = copy()
}
object roll extends app with grand[person] {
...
}
score:1
clone() is from java.lang.object not from java.lang.cloneable. cloneable is just a tagging-interface.
what you are trying probably does not work because implementing cloneable does not force the implementor to override the protected object.clone() with a public one.
see http://docs.oracle.com/javase/7/docs/api/java/lang/object.html#clone() and http://docs.oracle.com/javase/7/docs/api/java/lang/cloneable.html
ln conclusion: no it is not possible to clone an object of an arbitrary type t1. you could however clone any object of type t2 where t2 is bound by a type with a public override of clone(). your example fails because object.clone() is protected, i.e. can only be called from within a subclass.
Source: stackoverflow.com
Related Query
- Scala method clone in class Object cannot be accessed in T Access to protected method clone not permitted because
- Scala 2.12.4: Cannot access protected static Java method from another package anymore
- Why is my companion object cannot access method in its companion class
- jooq + scala code generation: method createIndex in object AbstractKeys cannot be accessed in object org.jooq.impl.AbstractKeys
- Access inner class method with "fine" syntax in Java using Scala class & object
- Scala type classes "view as" - cannot access method in companion object
- Scala "constructor DCAwareRoundRobinPolicy in class DCAwareRoundRobinPolicy cannot be accessed in object CassandraConnector"
- Method cannot be accessed in Macro generated class
- How to access a Java static method from Scala given a type alias for that class it resides in
- Can't access method of companion class from companion object
- Companion object cannot access private variable on the class
- Scala abstract class method that returns a new corresponding class child object
- Scala what is the difference between defining a method in the class instead on the companion object
- Scala "constructor Stopwatch cannot be accessed in class Main"
- Scala Implicit Method Compilation when Method Tries to Access Non-Existing Case Class Members
- How do I stub out a protected method in a object in scala
- scala - how to access a case class method from another class?
- Access from Java a Scala object that inherits from a generic Java base class
- Access companion object from case class (or vice-versa) using scala type macros
- Why can a companion object access a private val in its companion class when compiling, but cannot do that when interpreting?
- How can I access the companion object of a Scala class passed as a type param?
- How to access scala object inside scala class in java?
- Which is faster for comparing case class object in scala : a) equals(==) method or b) equating hash values
- How to call the object method (not class method) using reflection in scala
- How do I create a class hierarchy of typed factory method constructors and access them from Scala using abstract types?
- RESTEasy cannot call my annotated method on a scala class
- Scala cannot access object classes
- scala - Cannot override protected variable of java class
- I am implementing factory design pattern in Scala and got a compilation error when I tried to access a child class method
- Scala class method with WSClient call inside an object in play framework
More Query from same tag
- In Scala how can I reflect on a typedef (eg. type Data = Map[String,Any])?
- Checked Exception Variance
- For comprehension and Futures is having a type mismatch
- Show the names of nodes and edges using GraphStream in scala
- Save spark DataFrame to csv file with map<string,string> column type
- Adding logging if return value is None
- When I make fat Jar, is it ok to use different Scala version in EMR?
- Scala, type of constructor currying
- How to run sbt tests for debugging when debug is disabled by default?
- How to test Scala macros?
- Confusing construction order with lazy val
- LDAP for authentication and authorization in Playframework 2.0
- Anonymous functions in println in Scala
- How to write a Scala regular expression to capture all the quoted contents between two double quotes(including the escaped quote marks)?
- How to insert documents into a Mongo Time Series collection using scala driver
- scala method vs function partial application
- Scala/Java : Compare two list/set and removed matched element from both list
- Manually marking flyway migration as completed
- postRestart and preRestart methods are not getting invoke in akka actots
- how do I know if these two versions of scala are exactly the same?
- Array functor exercise
- Scala object extends abstract class/trait, access companion class fields
- Error Calling Generic Function In Scala
- how to merge two RDD to one RDD
- How to return boolean if column contains integer value instead of searching millions of records using spark dataframe
- Why does Scala ConcurrentMap.putIfAbsent always try to put?
- JSON Reads/Writes/Format Combinators Play - Use different key name while creating json
- How to split Array of Json DataFrame into multiple possible number of rows in Scala
- What is the meaning of a generic type like "C: ClassTag : Manifest"?
- Spark SQL combine Array[string] with mark