superclass

Java Web Services/JAXB - Abstract superclass

╄→гoц情女王★ 提交于 2019-11-29 08:33:16
问题 I have a package with JAXB annotated classes with an abstract superclass. I want to use this superclass in web service interface, so I can pass any of subclasses as a parameter. When I do it, an exception is thrown: javax.xml.ws.WebServiceException: javax.xml.bind.UnmarshalException - with linked exception: [javax.xml.bind.UnmarshalException: Unable to create an instance of xxx.yyy.ZZZ - with linked exception: [java.lang.InstantiationException]] It is possible to manually marshall/unmarshall

Preventing a class from direct instantiation in Python

喜欢而已 提交于 2019-11-28 21:05:31
问题 I have a super class with a method that calls other methods that are only defined in its sub classes. That's why, when I create an instance of my super class and call its method, it cannot find the method and raises an error. Here is an example: class SuperClass(object): def method_one(self): value = self.subclass_method() print value class SubClassOne(SuperClass): def subclass_method(self): return 'subclass 1' class SubClassTwo(SuperClass): def subclass_method(self): return 'nubclass 2' s1 =

Getting the name of a sub-class from within a super-class

谁都会走 提交于 2019-11-28 20:59:37
Let's say I have a base class named Entity . In that class, I have a static method to retrieve the class name: class Entity { public static String getClass() { return Entity.class.getClass(); } } Now I have another class extend that. class User extends Entity { } I want to get the class name of User: System.out.println(User.getClass()); My goal is to see "com.packagename.User" output to the console, but instead I'm going to end up with "com.packagename.Entity" since the Entity class is being referenced directly from the static method. If this wasn't a static method, this could easily be solved

How to determine if an object is an instance of certain derived C++ class from a pointer to a base class in GDB?

风流意气都作罢 提交于 2019-11-28 16:49:52
I'm debugging a C++ program with GDB. I have a pointer to an object of certain class. The pointer is declared to be of some super class which is extended by several sub-classes. There is no fields in the object to specify the precise class type of this object but some virtual functions (e.g. bool is_xxx()) are defined to tell the class type at runtime. Is there some way to tell the precise class type of an object in GDB without calling these virtual functions. Calling such functions in GDB may generate confusing result when the program is multi-threaded. Use ptype . If you use it by itself,

Inheritance and Overriding __init__ in python

无人久伴 提交于 2019-11-28 15:24:16
I was reading 'Dive Into Python' and in the chapter on classes it gives this example: class FileInfo(UserDict): "store file metadata" def __init__(self, filename=None): UserDict.__init__(self) self["name"] = filename The author then says that if you want to override the __init__ method, you must explicitly call the parent __init__ with the correct parameters. What if that FileInfo class had more than one ancestor class? Do I have to explicitly call all of the ancestor classes' __init__ methods? Also, do I have to do this to any other method I want to override? The book is a bit dated with

Is protected method in super class visible in sub class in a different package? [duplicate]

邮差的信 提交于 2019-11-28 14:17:17
This question already has an answer here: What is the difference between public, protected, package-private and private in Java? 25 answers It seems very silly, but I am really confused. Please see below code: package com.one; public class SuperClass { protected void fun() { System.out.println("base fun"); } } ---- package com.two; import com.one.SuperClass; public class SubClass extends SuperClass{ public void foo() { SuperClass s = new SuperClass(); s.fun(); // Error Msg: Change visibility of fun() to public } } I have read from oracle doc and here as well, that protected members are visible

super keyword without extends to the super class

梦想的初衷 提交于 2019-11-28 12:32:25
There is a simple program, in the constructor, super() is called without extends to the super class, I can not understand what will does this in this situation ? public class Student { private String name; private int rollNum; Student(String name,int rollNum){ super();// I can not understand why super keyword here. this.name=name; this.rollNum=rollNum; } public static void main(String[] args) { Student s1 = new Student("A",1); Student s2 = new Student("A",1); System.out.println(s1.equals(s2)); } } JB Nizet Every class that doesn't explicitly extend another class implicitly extends java.lang

Jackson serialization: how to ignore superclass properties

百般思念 提交于 2019-11-28 10:42:47
I want to serialize a POJO class which is not under my control, but want to avoid serializing any of the properties which are coming from the superclass, and not from the final class. Example: public class MyGeneratedRecord extends org.jooq.impl.UpdatableRecordImpl<...>, example.generated.tables.interfaces.IMyGenerated { public void setField1(...); public Integer getField1(); public void setField2(...); public Integer getField2(); ... } You can guess from the example that that this class is generated by JOOQ, and inherits from a complex base class UpdatableRecordImpl which also has some bean

How to call parent class' method from a subclass in JavaScript so that parent's local variables would be accessible?

こ雲淡風輕ζ 提交于 2019-11-28 09:58:32
问题 I'm using one of the approaches to class inheritance in JavaScript (as used in the code I'm modifying), but do not understand how to attach additional functionality for a method in a subclass to the functionality the respective parent class method already has; in other words, I want to override a parent's method in the child class with a method that besides its own sub-class-specific stuff does also the same the parent's method is doing. So, I'm trying to call the parent's method from the

Python: RuntimeError: super-class __init__() of %S was never called

拟墨画扇 提交于 2019-11-28 00:55:56
I tried to do some operation ( setParent ) on an object in Python (an instance of a class which inherits from a different class - to be specific, QtGui.QLabel ), but during runtime the above error was raised. The object itself has had some fields with actual content (verified on debug), but from some reason I couldn't "use" it. What does the error mean and how can I fix it? For some additional information, I shall say that the object was returned from a static method before I tried to do this operation on it. The subclass has a __init__() function of its own: def __init__(self, image, father):