Is there a way to omit a variable from a superclass?

My application class uses a library that uses two variables by default.

   // A class from framework:

public class SuperClass implements Serializable {

  private long id;
  private long version;

  // getter and setter methods for these variables...

}

I have to extend this class in order to get access to some functions of the framework.

If I extend this class to my class as follows:

public class MyClassChild extends SuperClass {

  private long myprimarykey;
  private String some column;
  private long myversion;

  // getter and setter methods for these variables...

}

According to the programming model, these two variables are also available. When performing an operation that requires an object of type SuperClass.

Is there any idea to extend this SuperClass that doesn't include these two variables (id, version)?

I do not know what to do?

Any suggestions pls?

thank

+3
source share
5 answers

JPA , :

public class MyClassChild extends SuperClass {

  private long myprimarykey;
  private String some column;
  private long myversion;  

  // Override superclass mappings
  @Transient
  long getId() { return super.getId(); }
  @Transient
  void setId(long id) { return super.setId(long id); }
  // etc...
}

, @AttributeOverride,

@AttributeOverride(name="id", column=@Column(name="EMP_ID"))
@Entity
public class MyClassChild extends SuperClass {

  private String some column;
  ...
}
+1

, - , ( , , , protected ). , , . , , .

+3

. , . , .

, , - , ? ...

+1

, , , .

+1

When you extend a class, you are supposed to add more variables and methods, you cannot subtract.

0
source

Source: https://habr.com/ru/post/1776148/


All Articles