Handling Methods which return Objects
I have a class called GenericObjectQueue, which essentially maintains a queue of objects.There is a method called getTopObject() which returns the first Object in the queue.
I use this class to maintain a queue "CustomerQ" of objects of the class "Customers ".Now when i write the following statements i get an error
customer firstcust= new customer();
firstcust= CustomerQ.getTopObject();
The compiler says incompatible types,
found : java.lang.Object
required: customer
How do I deal with this?
Thanks...RJ2
method called getTopObject() which returns the first
Object in the queue.Another way is to set the return type as 'Customer' in place of Object and return a Custome
Similar Messages
-
Function or method which returns the full PDC path of webdynpro iview
Hi All,
I have created a webdynpro application and created a webdynpro Iview in portal and attached this view to a role. I am looking for any standard function module or method which returns the full PCD path of the webdynpro iview, when it executed from portal.
Regards,
H.K.Hayath Basha.Well in ABAP, we don't have portal APIs to access potal catalog info.
The only available Portal Interface is IF_WD_PORTAL_INTEGRATION
Abhi -
What is the advantage of using methods to return objects?
Hello there,
What is the advantage of using static methods to return
objects? Isnt this a Factory Pattern ?
What is the real advantage of using methods to return objects
rather than using public constructors to create objects ?
Can some one please explain
RegardsI think there were two questions. The first (why
static) is well answered but I hope somebody can
answer the general question - why whatever =
createSomething(); as opposed to whatever
= new Something(); - because inquiring minds
want to know.I thought I answered that question. Perhaps I need to be more specific.
For the Singleton pattern, you don't want a new instance (except possibly the first time, if you're using lazy instantiation).
For the Factory pattern, you might not always want an instance of the actual class containing the static methods, so new won't work.
If, on the other hand, neither of the above holds, there is no reason not to use new (unless, of course, anyone can come up with another use of static creators).
RObin -
J2me Mobile client calling method which return byte[]
java.rmi.MarshalException: Expected Byte, received: SGVsbG8gV29ybGQ=
WebService1_Stub ws=new WebService1_Stub();
try {
String s=ws.getStringHelloWorld();// works fine
byte s[]=ws.helloWorld(); // error java.rmi.MarshalException: Expected Byte, received: SGVsbG8gV29ybGQ=
}catch(Expception e){
ex.printStackTrace();
}This same ws working fine in java standalone application please guide me what can be a problem ??
Regards
Haroon Idreesclear your app. server logs ( or make copies of them if will you need them) and redo the whole process. check out the logs and you should see some reason for this. i do not know if Borland's logs will turn out helpful, but it did help me out in certain other situations.
-
Defining enum with abstract method which returns a generic type
Is it possible to define an abstract method which returns an geneic type like below? Thanks
public enum Type{
A{
public List<Integer> getData(){}
B{
public Set<String> getData{}
abstract<T> T getData();
}vulee wrote:
Why not?
List<Integer> lst = Type.A.getData();Wonder, which compiler you use. Can't be Java6:
# javac Enums.java
Enums.java:23: incompatible types
found : java.util.Collection<capture#376 of ?>
required: java.util.List<java.lang.Integer>
List<Integer> data = Type.A.getData();
^
1 errorEdit: Unless you do it the generic way as you proposed, which actually is a phoney. Because of the T being a generic method parameter, the compiler will infer it from the type of the variable it gets assigned to. Hence, both of the following will compile:
List<Integer> lst = Type.A.getData();
Set<String> lst2 = Type.A.getData(); // Runtime exceptionActually, javac is telling you that giving warnings on the enum constants redefined method return types.
Edited by: stefan.schulz on Sep 10, 2008 11:38 PM -
How do I deal with a Java method which returns a class object?
Hi, I am using JNI to talk to some Java code from c++;
I have a java method in class B that is defined as
class B{
A[] As;
A getA(int i){
return As(i);
where A is one of my classes.
I would like to know the code to deal with a returned object of type A and then how to access the variables in A from c++.
I have defined my method pointer as :
env->GetMethodID(B, "getA", "(I)A;");and have the jclass object of type A.
Would I do something like jclass A_CLASS = env->FindClass("A");
jobject A_OBJECT = (A_CLASS)env->CallObjectMethod(B,getA, i) ; If so, how do I then access the fields in A_OBJECT? Please let me know, thanks.ilganeli wrote:
Thanks but this doesn't really help. I know how this is done in Java (see below).Presumably you also understand how that code will fail. At least based on what you have posted here.
I do not understand the syntax to do the equivalent thing in JNI, specifically, how to cast the returned object from the CallObjectMethod function to be of the appropriate type, namely A, and then how to access those fields. You don't cast it. Didn't do so in your java code either.
But you define how you are going to attempt to access any object in JNI. If you mess up it fails. -
Autotype ant task and java source file having method which returns hashmap
Hi Friends,
I am using autotype ant task to generate types.xml and supporting java classes.
The task is defined as follows .
<target name="std">
<source2wsdd javaSource="HelloWorld.java"
typesInfo="types.xml"
ddFile="ddfiles/web-services.xml"
serviceURI="/HelloWorldService"/>
</target>
In my java source i have method which is returning an HashMap. In this scenario I am getting error when i run the task. The error is as follows
C:\test-ws\javaclass>ant auto
Buildfile: build.xml
auto:
[autotype] Autotyping for javaTypes TestBean
[autotype] weblogic.xml.schema.binding.BindingException: Invalid class received
: interface java.util.Map loaded from file:/C:/bea/jdk142_05/jre/lib/rt.jar!/jav
a/util/Map.class. All classes that will be serialized or deserialized must be n
on-interface, non-abstract classes that provide a public default constructor
[autotype] at weblogic.xml.schema.binding.internal.codegen.JavaInspector.en
sureValidClass(JavaInspector.java:1050)
[autotype] at weblogic.xml.schema.binding.internal.codegen.JavaInspector.fi
llDescriptor(JavaInspector.java:174)
[autotype] at weblogic.xml.schema.binding.internal.codegen.JavaInspector.ge
tDescriptor(JavaInspector.java:139)
[autotype] at weblogic.xml.schema.binding.internal.codegen.JavaInspector.cr
eateBeanProperty(JavaInspector.java:927)
[autotype] at weblogic.xml.schema.binding.internal.codegen.JavaInspector.cr
eateBeanProperty(JavaInspector.java:905)
[autotype] at weblogic.xml.schema.binding.internal.codegen.JavaInspector.ad
dPropertiesToScalar(JavaInspector.java:834)
[autotype] at weblogic.xml.schema.binding.internal.codegen.JavaInspector.fi
llDescriptor(JavaInspector.java:209)
[autotype] at weblogic.xml.schema.binding.internal.codegen.JavaInspector.ge
tDescriptor(JavaInspector.java:139)
[autotype] at weblogic.xml.schema.binding.internal.codegen.JavaInspector.cr
eateDescriptorForClass(JavaInspector.java:106)
[autotype] at weblogic.xml.schema.binding.internal.codegen.Compiler.compile
(Compiler.java:106)
[autotype] at weblogic.xml.schema.binding.internal.XSDTypeMappingBuilder.ma
pClass(XSDTypeMappingBuilder.java:89)
[autotype] at weblogic.xml.schema.binding.internal.XSDTypeMappingBuilder.ma
pClass(XSDTypeMappingBuilder.java:102)
[autotype] at weblogic.xml.schema.binding.internal.TypeMappingBuilderBase.a
ddMapping(TypeMappingBuilderBase.java:180)
[autotype] at weblogic.webservice.tools.build.internal.Java2SchemaImpl.doTy
peMapping(Java2SchemaImpl.java:267)
[autotype] at weblogic.webservice.tools.build.internal.Java2SchemaImpl.run(
Java2SchemaImpl.java:167)
[autotype] at weblogic.ant.taskdefs.webservices.javaschema.JavaSchema.doJav
a2Schema(JavaSchema.java:302)
[autotype] at weblogic.ant.taskdefs.webservices.javaschema.JavaSchema.execu
te(JavaSchema.java:184)
[autotype] at org.apache.tools.ant.Task.perform(Task.java:341)
[autotype] at org.apache.tools.ant.Target.execute(Target.java:309)
[autotype] at org.apache.tools.ant.Target.performTasks(Target.java:336)
[autotype] at org.apache.tools.ant.Project.executeTarget(Project.java:1339)
[autotype] at org.apache.tools.ant.Project.executeTargets(Project.java:1255
[autotype] at org.apache.tools.ant.Main.runBuild(Main.java:609)
[autotype] at org.apache.tools.ant.Main.start(Main.java:196)
[autotype] at org.apache.tools.ant.Main.main(Main.java:235)
BUILD FAILED
file:C:/test-ws/javaclass/build.xml:62: weblogic.webservice.tools.build.WSBuildE
xception: Failed to do type mapping - with nested exception:
[weblogic.xml.schema.binding.BindingException: Invalid class received: interface
java.util.Map loaded from file:/C:/bea/jdk142_05/jre/lib/rt.jar!/java/util/Map.
class. All classes that will be serialized or deserialized must be non-interfac
e, non-abstract classes that provide a public default constructor]
Can any one provide the solution for this
Thanks
AnanthaHi Friends,
I am using autotype ant task to generate types.xml and supporting java classes.
The task is defined as follows .
<target name="std">
<source2wsdd javaSource="HelloWorld.java"
typesInfo="types.xml"
ddFile="ddfiles/web-services.xml"
serviceURI="/HelloWorldService"/>
</target>
In my java source i have method which is returning an HashMap. In this scenario I am getting error when i run the task. The error is as follows
C:\test-ws\javaclass>ant auto
Buildfile: build.xml
auto:
[autotype] Autotyping for javaTypes TestBean
[autotype] weblogic.xml.schema.binding.BindingException: Invalid class received
: interface java.util.Map loaded from file:/C:/bea/jdk142_05/jre/lib/rt.jar!/jav
a/util/Map.class. All classes that will be serialized or deserialized must be n
on-interface, non-abstract classes that provide a public default constructor
[autotype] at weblogic.xml.schema.binding.internal.codegen.JavaInspector.en
sureValidClass(JavaInspector.java:1050)
[autotype] at weblogic.xml.schema.binding.internal.codegen.JavaInspector.fi
llDescriptor(JavaInspector.java:174)
[autotype] at weblogic.xml.schema.binding.internal.codegen.JavaInspector.ge
tDescriptor(JavaInspector.java:139)
[autotype] at weblogic.xml.schema.binding.internal.codegen.JavaInspector.cr
eateBeanProperty(JavaInspector.java:927)
[autotype] at weblogic.xml.schema.binding.internal.codegen.JavaInspector.cr
eateBeanProperty(JavaInspector.java:905)
[autotype] at weblogic.xml.schema.binding.internal.codegen.JavaInspector.ad
dPropertiesToScalar(JavaInspector.java:834)
[autotype] at weblogic.xml.schema.binding.internal.codegen.JavaInspector.fi
llDescriptor(JavaInspector.java:209)
[autotype] at weblogic.xml.schema.binding.internal.codegen.JavaInspector.ge
tDescriptor(JavaInspector.java:139)
[autotype] at weblogic.xml.schema.binding.internal.codegen.JavaInspector.cr
eateDescriptorForClass(JavaInspector.java:106)
[autotype] at weblogic.xml.schema.binding.internal.codegen.Compiler.compile
(Compiler.java:106)
[autotype] at weblogic.xml.schema.binding.internal.XSDTypeMappingBuilder.ma
pClass(XSDTypeMappingBuilder.java:89)
[autotype] at weblogic.xml.schema.binding.internal.XSDTypeMappingBuilder.ma
pClass(XSDTypeMappingBuilder.java:102)
[autotype] at weblogic.xml.schema.binding.internal.TypeMappingBuilderBase.a
ddMapping(TypeMappingBuilderBase.java:180)
[autotype] at weblogic.webservice.tools.build.internal.Java2SchemaImpl.doTy
peMapping(Java2SchemaImpl.java:267)
[autotype] at weblogic.webservice.tools.build.internal.Java2SchemaImpl.run(
Java2SchemaImpl.java:167)
[autotype] at weblogic.ant.taskdefs.webservices.javaschema.JavaSchema.doJav
a2Schema(JavaSchema.java:302)
[autotype] at weblogic.ant.taskdefs.webservices.javaschema.JavaSchema.execu
te(JavaSchema.java:184)
[autotype] at org.apache.tools.ant.Task.perform(Task.java:341)
[autotype] at org.apache.tools.ant.Target.execute(Target.java:309)
[autotype] at org.apache.tools.ant.Target.performTasks(Target.java:336)
[autotype] at org.apache.tools.ant.Project.executeTarget(Project.java:1339)
[autotype] at org.apache.tools.ant.Project.executeTargets(Project.java:1255
[autotype] at org.apache.tools.ant.Main.runBuild(Main.java:609)
[autotype] at org.apache.tools.ant.Main.start(Main.java:196)
[autotype] at org.apache.tools.ant.Main.main(Main.java:235)
BUILD FAILED
file:C:/test-ws/javaclass/build.xml:62: weblogic.webservice.tools.build.WSBuildE
xception: Failed to do type mapping - with nested exception:
[weblogic.xml.schema.binding.BindingException: Invalid class received: interface
java.util.Map loaded from file:/C:/bea/jdk142_05/jre/lib/rt.jar!/java/util/Map.
class. All classes that will be serialized or deserialized must be non-interfac
e, non-abstract classes that provide a public default constructor]
Can any one provide the solution for this
Thanks
Anantha -
Looping over method which returns a query
HI,
I have a method that returns a query, I pass into this method
a ID number, which the query uses in the where clause. Now I have
another query which returns a list of ID numbers that I loop
through calling the first method and passing in the ID number, for
example
methodA
loop through methodA results
call methodB passing in methodA.ID
get results from methodB
close loop
now the problem I'm having is that methodB returns a query
and I want to be able to return the results from methodB as one
single query structure. I'm not sure how many times I will loop
through the results from methodA, it could be twice, it could by
ten time. So the results from calling methodB could be very large.
How can I add the results from methodB into one single query
structure?how about creating an empty query with cfset newQuery =
QueryNew([list of columns]);
and then on each loop through method B add a new row to this
new query, and then return that query as result? -
Ajax call method which return json Data
Hi, I make one function , which i want to return json value , for this which return type i mention in function:
This is javascript which call Retrieve method.
<script>
debugger;
var remoteDatasource = new kendo.data.DataSource({
transport: {
read: {
type:"POST",
url: "Controllers/Home.cfc",
dataType: "json",
data: {
method: "Retrieve",
dataLists: JSON.stringify(request)
</script>
Home.cfc
component
remote function Retrieve(string dataLists)
try
q = new Query();
q.setsql("SELECT * FROM Product");
qResult = q.execute().getresult();
col_len = ListLen(qResult.Columnlist);
dataArray = ArrayNew(1);
row = 0;
col = 0;
for(row = 1; row <= len; row++)
for(col = 1; col <= col_len; col++)
FieldName = ListGetAt(qResult.Columnlist, col);
dataArray[row][col] = qResult[FieldName][col];
jsonvar=serializeJSON(dataArray);
catch(any e)
return jsonvar;One can see immediately that you have to make the following corrections, at least:
Give the query a name;
Point the query to a datasource;
Define the variable 'len' (even better, use a different, less confusing, name for the variable). -
Invoking Methods to receive Object.Please Respond
Hello there,
What is the advantage of defining methods that
return an object ?
For e.g,the InetAddress class has no constructors.Rather
we need to call the getByName() method whch returns an
InetAddress Object.
What is the advantage of doing this? Is this the way
we define factory methods which return objects?
So can we say that the InetAddress Class is a factory class?
RegardsThis class serves however as its own factory, in the
sense, that objects of this type can be obtained with
the help of the folling methods:
static InetAddress[] getAllByName(String host)
Determines all the IP addresses of a host,
f a host, given the host's name.
static InetAddress getByName(String host)
Determines the IP address of a host, given
st, given the host's name.
I am not so sure if either of these methods qualify as factory methods, their main purpose is not the creation of the object(s), but to find particular instances based on some criteria, the fact that they may or may not be created as a result of calling these methods is purely incidental. In my humble opinion that is... -
Calling a method that returns an object Array
Hello.
During a JNICALL , I wish to call a method which returns an object array.
ie my java class has a method of the form
public MyObject[] getSomeObjects(String aString){
MyObject[] theObjects=new MyObject[10];
return theObjects
Is there an equivalent to (env)->CallObjectMethod(...
which returns a jobjectArray instead of a jobject, and if not could somebody suggest a way around this.
Thanks,
NeilI believe an array oj jobjects is also a jobject. You can then cast it to another class.
-
How to Call Event Handler Method in Another view
Hi Experts,
Can anybody tell me how to call Event handler Method which is declared in View A ,it Should be Called in
view B,Thanks in Advance.
Thanks & Regards
Santhoshhi,
1) You can make the method EH_ONSELECT as public and static and call this method in viewGS_CM/ADDDOC using syntax
impl class name of view GS_CM/DOCTREE=>EH_ONSELECT "method name.
or
2)The view GS_CM/ADDDOC which contains EH_ONSELECT method has been already enhanced, so I can't execute such kind of operation one more time.
or
3)If both views or viewarea containing that view are under same window , then you can get the instance ofGS_CM/DOCTREE from view GS_CM/ADDDOC through the main window controller.
lr_window = me->view_manager->get_window_controller( ).
lv_viewname = 'GS_CM/DOCTREE '.
lr_viewctrl ?= lr_window ->get_subcontroller_by_viewname( lv_viewname ).
Now you can access the method of view GS_CM/DOCTREE .
Let me know in case you face any issues.
Message was edited by: Laure Cetin
Please do not ask for points, this is against the Rules of Engagement: http://scn.sap.com/docs/DOC-18590 -
How to define method witch returning an array in View, using method wizard
Dear experts.
I would like to define method which returning an array in View.
When View is opened, in "Methods" tab push "new" button, then select "Method" in Method Type window,
push "Next" but in Method Properties window Array Type checkbox is disabled. So, it is not possible to
define method with returning array type.
Please anybody, help me to resolve this problem.Hi
While creating method, you can see a check box over there as array type just check it that array type check box,
or
You can selet java native type as array by selecting "java native type"
thanks
anup
Edited by: Anup Bharti on Oct 15, 2008 8:50 AM
Edited by: Anup Bharti on Oct 15, 2008 8:51 AM -
How to code a method that returns string for class object
I have a class named Address.
public class Addresss{
private String street;
private String city; // instance variables
private String zipcode;}I have been asked to write a method that returns a string for Address object. I dont understand how to create address object.Can anyone pls help me understand.
do I have to write (for creating object)
Address addressObject = new Address(); ( coding method that returns a string for address object) ---> I really dont understand this part.looks almost right. The problem is that your method name AddressBookEntry does not match the name of your class AddressBook and therefore is not a constructor.
Furthermore, you probably need to make a distinction between a single entry into the address book which consists of a single name and a single address, (which is just what you have done) and an address book itself which is probably a list of AddressBookEntries
So for your code I would change the class that you called "AddressBook" to "AddressBookEntry" and have a third class that represents the collection of AddressBookEntries.
Now to be honest, I don't know why you keep the name split apart from the street address portion of the address. I would be more inclined to keep the name as a field of the address itself, but it's your code, you carve it up the way you like. -
Design question: methods returning objects
I have a general design question. When, in general (and why), should you have a method alter an object via it's methods but not return the object as opposed to doing the same operation in a method and then return it.
Consider the two below methods which do basically the same thing. When is one desireable over the other, and why?
Cheers--
public void setMyIntField(SomeObject pObj){
pObj.setSomeInt(5);
public SomeObject setMyIntField(SomeObject pObj){
pObj.setSomeInt(5);
return pObj;
}Let me give a better example:
class FruitWorker{
private void someMethod(){
HashMap myCitrus = new HashMap();
HashMap myTropicals = new Hashmap();
// use my no return obj method
addFruitProps1(myCitrus,
"tartnes",
new FruitProperty("very!" ));
// use my return object method
myTropicals = addFruitProps2(myCitrus,
"sweetness",
new FruitProperty("little bit" ));
}// end method
private void addFruitProperties1(HashMap pFruitProps,
String pProp
FruitProperty pVal){
pFruitProps.add( pProp,pVal);
}// end method
private HashMap addFruitProperties2(HashMap pFruitProps,
String pProp
FruitProperty pVal){
pFruitProps.add( pProp,pVal);
return pFruitProps;
}// end method
}// end class
Maybe you are looking for
-
Hello, My old computer conked out and I was able to back up my iTunes library, now I'm trying to imprt them on my new computer, and it seems to take forever, and sometimes after it's done 'importing' it doesn't show up in my library. I've tried the '
-
How can I unlock iPhoto on a locked disc after installing Mavericks?
How can I unlock Iphoto from a locked disc after I installed mavericks?
-
What is BP Password field used for?
Hi Experts, Can you tell me what the BP Password field on the general tab is used for, if anything? Also, can you explain what BP Channel Code is used for? Thanks, Lang
-
SQL Help with Time Period vs Time Period Comparison
Hello, I am trying to create a query that will provide me a result set that will have current revenue (based off user selection of time) compared to another set of revenue with a different time period. For example: select a.xx_adm_adv_id, a.xx_editio
-
i tried to restore my iphone due to my apps always freezing and my phonen always restarting by itself, and i keep getting a message that says "the iphone software update server could not be contacted. make sure your network settings are correct and y