Class implements Cloneable?
Is it possible for a class to implement Cloneable in JavaME - as I can't seem to get it to work.
Thanks
No, the Cloneable interface isn't part of Java ME. You could have found that out yourself by checking the Javadocs for JSR-118 and JSR-139.
db
Similar Messages
-
Abstract class implements Cloneable... How?
I have an abstract class that is inherited by many many subclasses. I wish to make this abstract class a cloneable.
Most of the subclasses are using the protected fields inherited from the abstract one, they almost never add any extra field. So it would make a lot of sense to implement the clone() method at the abstract level. And not doing so would cost me a lot of time.
But that causes me trouble, because you can't write something like this :
public abstract class MyAbstractClass implements Cloneable {
protected Source source; // the two fields the subclasses are satisfied with, most the time
protected Vectro<Target> targets;
public Effect clone() {
return new Effect(source , targets); // when a subclass has extra fields, I plan to overwrite clone()
}Because you can't instantiate an abstract class, of course. Anyway, I'd rather instatiate a class of the appropriate concrete class.
I feel there is a way to hack this. I feel there is a way to avoid having to write the same clone() method in every subclass.
Anyone?
Thanks.jverd wrote:
bestam wrote:
Most of the subclasses are using the protected fields inherited from the abstract one, Bad idea. Make the fields private and provide protected get/set methods.Is this a general recommendation or only in the context described by the OP?
Because API classes don't do this in many cases. Just looked at a random one: AbstractButton. -
How to specify that a generic type should implement cloneable ?
Hi everybody,
I created a map type called StringMap as such
class StringMap<V>{
HashMap<String,V> map;
and now, I want to implement the method clone() in my StringMap, for that I would like to use the method V.clone()
but I get an error saying "The method clone() from type Object is not visible". This is logical since clone() is protected in Object class. So I believe a solution would be to specify that V implements the interface Cloneable(). This tried this:
class StringMap<V implements Cloneable>{
but it doesn't work.
Do you know a way to do it ?
Thanksdubwai wrote:
r035198x wrote:
You can say <V extends Cloneable> instead.That still won't solve the root issue. The Cloneable interface has no methods and implementing it will not expose clone(). Cloneable is broken.Yep, I was hoping the OP would pick that up after that. -
Class implementation for interface
Hello,
I am a beginner in ABAP Objects.
In the coding of method if_swf_ifs_workitem_exit~event_raised of class CL_SWF_UTL_EXIT_NEW
There is the instruction follow :
*Get the workflow container
irh_container ?= im_workitem_context-> get_wf_container()
Im_workitem_context is interface type "IF_WAPI_WORKITEM_CONTEXT"
If I execute in debug mode I see the implemtation class of this interface (im_workitem_context) is "CL_SWF_RUN_WORKITEM_CONTEXT"
But where this information of implementation is defined ? (I saw nothing)
Regards
Christine
Edited by: chris_75 on Sep 7, 2010 4:22 PMInterfaces allow to implement highly scalable object oriented applications.
Interface is a kind of a template for a real class which forces this class to implement methods defined in an interface.
The main characteristics of an interfaces are:
- they DO NOT contain any implementations (so there is nothing like INTERFACE ... IMPLEMENTATION - they have only DEFINITIONS - implementations are within classes)
- they have only PUBLIC sections.
Why we need an interface. The answer is simple:
We want to handle some objects uniformly from one application compotent, whereas these objects may behave differently inside.
Example:
Let's say we need to build a sorting program for numbers.
The program would have an interface variable L_RIF_SORTER of an interface LIF_SORTER. LIF_SORTER has a method definition SORT with an C_TAB changing parameter.
Sorting application would call the sorting algorithm as follows:
L_RIF_SORTER->SORT( CHANGING c_tab = l_tab ).
Now is the main point:
We want to have 2 kinds of sorting algorithms implemented, let's say BUBBLE SORT and QUICK SORT.
To do so, we implement 2 classes: LCL_BUBBLE_SORT and LCL_QUICK_SORT.
Both classes implement interface using the statment INTERFACES in a public section.
The user would have to choose the algorithm from an input field. Depending on the content of this field the sorting application would instantiate one class or the other using the statement:
CREATE OBJECT l_rif_sorter TYPE (variable_with_class_name).
THis is the point where ABAP gets to know the real object and its type behind the interface.
This approach is generally called the STRATEGY PATTERN. See Wikipedia for this.
I hope I answered your question.
Regards, -
How can I read the filter dependent values in abap class implementation ?
Hi Experts,
I need read the filter dependent values in my Z Class implementation but I don´t know how to do it.
In classic badi was via FT_VAL parameter.
Now how can I do it ?
Regars,
BalaRogerio,
In case of badis the field flt_val gets added automatically as an import parameter when you check FILTER DEPENDENT check box. This is to restrict which implementation of the badi should be executed, if there are more than one.
There is no such concept when you are building a class.
If you want one of your methods to be executed on in certain cases, you need add the required logic within the method.
If you are referring to the FILTER check box in the pic below, that is used for a different purpose. It is used to filter what is displayed on the class builder screen. F1 on the field to know more about the same.
Thanks,
Vikram.M -
Internal class implementing interface extending abstract interface :P
Confused ha? Yeah me too. RIght here it goes.
Theres an abstract interface (abstractIFace) that has for example method1() method2() and method3(). There are two other interfaces iFace1 and iFace2 that extend abstractIFace. Still with me? :P iFace1 only uses method2() whereas iFace2 uses method1(), method2() and method3(). Internal classes implementing these are then used. The reason is so that when returning an object one method can be used that will return different types of objects. But this doesnt work. It says that all the classes in the abstractIFace must be used/implemented but I only want method2() in iFace1 and all in iFace2.
Just say what the f*ck if this is too confusing cos i think it is and i did a crap job explaining!! :Ppublic interface IFace {
void method1();
void method2();
void method3();
public class Test {
private static class Class1 implements IFace {
public void method1() {
System.out.println("method1");
public void method2() {
System.out.println("method2");
public void method3() {
System.out.println("method3");
private static class Class2 implements IFace {
public void method1() {
throw new UnsupportedOperationException();
public void method2() {
System.out.println("method2");
public void method3() {
throw new UnsupportedOperationException();
public static IFace createObject(boolean flag) {
return flag ? (IFace) new Class1() : new Class2();
} -
Can a class implements more than one interface?
Hello
Can a class implements more than one interface?
ThanksOf course, this doesn't mean that it won't be a problem though. If the two interfaces have methods with the same signature, but different return types, you won't be able to implement them together. I.E.
interface InterfaceA {
public int doSomething(String myString);
interface InterfaceB {
public String doSomething(String myString);
// Now the classes
// Gives error "Duplicate method doSomething(String) in type ClassA"
public class ClassA implements InterfaceA, InterfaceB {
public int doSomething(String myString) {
System.out.println("A");
return 0;
public String doSomething(String myString) {
System.out.println("B");
return 0;
// Gives error "The return type is incompatible with InterfaceB.doSomething(String)"
public class ClassB implements InterfaceA, InterfaceB {
public int doSomething(String myString) {
System.out.println("A");
return 0;
// Gives error "The return type is incompatible with InterfaceA.doSomething(String)"
public class ClassC implements InterfaceA, InterfaceB {
public String doSomething(String myString) {
System.out.println("B");
return 0;
} -
Hi ,
I want to call a java class implemented as a service in felix . This should be called after succesfull activation of the page .
I want to use ExtJs implemented in /libs/cq/ui/widgets/source/widgets/wcm/SiteAdmin.Actions.js file CQ.wcm.SiteAdmin.activatePage method.
Please suggest something on this .Hi Sham ,
i tried this ,
var response = CQ.HTTP.post(
CQ.shared.HTTP.externalize("/bin/replicate.json"),
callback,
{ "_charset_":"utf-8", "path":paths, "cmd":"Activate" }
if (CQ.HTTP.isOk(response)) {
CQ.HTTP.post("/bin/sample.json",
null,
{"_charset_":"utf-8","path":paths});
It is giving an alert messege on siteadmin screen as "Unspecified Error" .
What can be the problem , am i missing something here? -
Error "You may only define methods within "CLASS class IMPLEMENTATION"
We have code in LMIGOSMC so that the vendor batch number appears in the MIGO transaction for certain movement types. We have created another, custom movement type in which this functionality should be available so I need to add it to LMIGOSMC. When I go in and try to make the modification I am getting the following error:
"You may only define methods within "CLASS class IMPLEMENTATION ...ENDCLASS".
What am I doing wrong?Hi,
You are not doing anything wrong with regard to the syntax error you are getting. During the syntax check of include program LMIGOSMC, the system is not aware of the CLASS... ENDCLASS statements within the program LMIGOSM4. Try the syntax check at the LMIGOSM4 program level (or even better, at the SAPLMIGO level) and you will see that the error is not given.
Regards,
Jamie -
Is there any statement to indentify if a class implements an interface?
Is there any statement to indentify if a class implements a particular interface?
If you want to check if a class implements an interface, look up the interface here:
http://java.sun.com/j2se/1.4.2/docs/api/index.html
and look under "All Known Subinterfaces:"
If you want to check if an object is of that interface:if(yourObject instanceof SomeInterface)
// do something
} -
Implementing constructor outside class implementation..
REPORT ZTUSH.
CLASS counter DEFINITION.
PUBLIC SECTION.
METHODS CONSTRUCTOR.
CLASS-METHODS: set IMPORTING value(set_value) TYPE i,
increment,
get EXPORTING value(get_value) TYPE i.
PRIVATE SECTION.
CLASS-DATA count TYPE i.
ENDCLASS.
METHOD CONSTRUCTOR.
WRITE:/ 'I AM CONSTRUCTOR DUDE'.
ENDMETHOD.
CLASS counter IMPLEMENTATION.
METHOD set.
count = set_value.
ENDMETHOD.
ENDCLASS.
DATA cnt TYPE REF TO counter.
START-OF-SELECTION.
CREATE OBJECT cnt.
CALL METHOD counter=>set EXPORTING set_value = number.
I THOUGHT WE CAN DEFINE CONSTRUCTOR METHOD OUTSIDE CLASS IMPLEMENTATION AS IN JAVA. But when I do that I get an error, method can be implemented only withing class. Why?Hello Rajesh
I do not fully understand what you mean by "I THOUGHT WE CAN DEFINE CONSTRUCTOR METHOD OUTSIDE CLASS IMPLEMENTATION AS IN JAVA". However, if you mean that we can create an object without having an explicit CONSTRUCTOR method defined then this is possible in ABAP like in Java (see coding below).
Regards
Uwe
REPORT ztush.
* CLASS counter DEFINITION
CLASS counter DEFINITION.
PUBLIC SECTION.
*METHODS CONSTRUCTOR.
CLASS-METHODS: set IMPORTING value(set_value) TYPE i,
increment,
get EXPORTING value(get_value) TYPE i.
PRIVATE SECTION.
CLASS-DATA count TYPE i.
* NO explicit constructor
*METHOD CONSTRUCTOR.
*WRITE:/ 'I AM CONSTRUCTOR DUDE'.
*ENDMETHOD.
ENDCLASS. "counter DEFINITION
* CLASS counter IMPLEMENTATION
CLASS counter IMPLEMENTATION.
METHOD set.
count = set_value.
ENDMETHOD. "set
METHOD get.
ENDMETHOD. "get
METHOD increment.
ENDMETHOD. "increment
ENDCLASS. "counter IMPLEMENTATION
DATA cnt TYPE REF TO counter.
START-OF-SELECTION.
* Implicit constructor is called
CREATE OBJECT cnt.
CALL METHOD counter=>set
EXPORTING
set_value = 5.
END-OF-SELECTION. -
Abstract class implementation Dos Prompt
Hello everyone,
Good day! Anyone knows how to implement or use abstract class to another class. Pls.... help me. I'm still a novice programmer. Program like Bank Account with a abstract class named 'Account' and an another class 'Savings' extends the abstract class and also the third class named 'TimeDeposit' something like it.Hello everyone,
Good day! Anyone knows how to implement or
use abstract class to another class. Pls.... help
me. I'm still a novice programmer. Program like Bank
Account with a abstract class named 'Account' and an
another class 'Savings' extends the abstract class
and also the third class named 'TimeDeposit'
something like it.One thing to remember is that your class has to include code for all methods that are marked abstract in the abstract class you are extending; and if you don't want anyone else extending your class, you should make it final. You should also check the abstract class's constructors to see if you need to call a particular one when you are constructing your class. If you do, you'll need to call super(...) in your class's constructor, and it should be the first statement. -
Extend abstract class & implement interface, different return type methods
abstract class X
public abstract String method();
interface Y
public void method();
class Z extends X implements Y
// Compiler error, If I don't implement both methods
// If I implement only one method, compiler error is thrown for not
// implementing another method
// If I implement both the methods,duplicate method error is thrown by
//compiler
The same problem can occur if both methods throw different checked exceptions,or if access modifiers are different..etc
I'm preparing for SCJP, So just had this weired thought. Please let me know
if there is a way to solve this.Nothing you can do about it except for changing the design.
Kaj -
Public class implements interface
I am taking my first crack at interfaces: I have superclass A which is a parent of class B, which implements interface C. I need to use class B to make 3 variable instances within class A. I think I will use interface C to make calculations based on the 3 variables. Where do you recommend that I declare and set values for the 3 variables if I need to output the values at the top, in superclass A?
I'm just a little unclear on pulling these objcts together... thanks in advance.I am taking my first crack at interfaces: I have
superclass A which is a parent of class B, which
implements interface C. I need to use class B to make
3 variable instances within class A. I think I will
use interface C to make calculations based on the 3
variables. Where do you recommend that I declare and
set values for the 3 variables if I need to output the
values at the top, in superclass A?
I'm just a little unclear on pulling these objcts
together... thanks in advance. If your variables are going to be used by your superclass A then they had better be declared there. You can work with them whereever you want.
I'm not sure what you are saying about "...use interface C to make calculations based on the 3 variables." You can't do calculations inside an interface. Furthermore, if B extends A and implements C then A and C are going to be completely separate entities. Any reference to C, even if it is actually an object of type B, will not be able to use anything in A--unless you cast it to B, in which case there is no use in making an interface at all.
I probably just confused you, but oh well...
Jeff -
How to find out message in a class implementation.
Hi gurus,
I am implementing a class : CL_UKM_COMMITMENT_NOTIFICATION
with the method : II_UKM_COMMITMENT_NOTIFICATION~EXECUTE_ASYNCHRONOUS
The problem is, I am passing the required data to test it, but am not being able to find out the error, as the implementation is not working.
Is there a way I can find out the error????
Thanks in advance.Hi,
I am doing the same thing.
This class is supposed to post data,which is passed in the class, into a database table.
But after executing it, eventhought there is no error, and the sy-subrc value is 0, the data is not getting posted in the database table. I still cant find out where is the problem lying.
So, is there any other way to find that out?
Maybe you are looking for
-
Not able to create R/3 source system in BW
using sm59 when i go to R/3 and click on R3 logical name i get login screen , for r/3 if i give user id and name i am able to enter in r/3, What i should do so that i won't get this logon screen I have already done following according to posting in t
-
Error 403--Forbidden- From RFC 2068 Hypertext Transfer Protocol -- HTTP/1.1
I am getting the following error From RFC 2068 Hypertext Transfer Protocol -- HTTP/1.1: 10.4.4 403 Forbidden The server understood the request, but is refusing to fulfill it. Authorization will not help and the request SHOULD NOT be repeated. If the
-
Question About Using iPhone as Landline
My wife and I have had iPhones for about six months and love them. We've noticed that everyone is calling us on our iPhones, so we'd like to cancel our land lines. The problem is with hearing the ring. It's certain that I'm not going to be where the
-
Is there a way to shut off the start-up sound?
how do I turn off the start-up sound that plays when I turn on my macbook?
-
How do i get to see websites on full screen so i dont need to keep scrolling left and right?
before i could see the whole width of a webpage without scrolling left and right but now everything is bigger and i cant see the whole page without scrolling.