How to pass Method Inner Class reference to other method?
Hi All,
I am trying to pass the reference of "method inner class".
Can any one explain me how to pass the reference and where other method will sit in the class, I mean either in Outer Class or in Inner Class ?
Thanks in advance for ur reply :)
package methosInnerClass;
public class MethodLocalInnerClass {
private String outerName;
private static String statOuterName;
public MethodLocalInnerClass(String name, String statName) {
outerName = name;
statOuterName = statName;
public void methodWithLocallClass() {
class MethodInnerClass {
String innerName;
MethodInnerClass(String name) {
innerName = name;
public void displayOuterInner() {
System.out.println("Outer Name: " + outerName + "\nOuter StatName: " + MethodLocalInnerClass.statOuterName + "\nInner Name: " + innerName);
MethodInnerClass methodInner = new MethodInnerClass("Harish");
methodInner.displayOuterInner();
*Pass above reference to other method*
public static void staticMethodWithLocallClass() {
class MethodInnerClass {
String innerName;
MethodInnerClass(String name) {
innerName = name;
public void displayOuterInner() {
// We can not access the non-static instance variable since this method is a static method
//System.out.println("Outer Name: " + outerName + "\nOuter StatName: " + MethodLocalInnerClass.statOuterName + "\nInner Name: " + innerName);
System.out.println("Outer StatName: " + MethodLocalInnerClass.statOuterName + "\nInner Name: " + innerName);
new MethodInnerClass("Shakshi").displayOuterInner();
public static void main(String[] args) {
new MethodLocalInnerClass("Abhishek","Neeshu").methodWithLocallClass();
System.out.println("Calling innerClass within static method !!!");
staticMethodWithLocallClass();
}
package donald.test.inner_class;
public class OutterClass {
private String outerName;
private final OutterClass outterClass;
public OutterClass() {
outterClass = this;
public void methodWithInnerClass(final String strValueToPassToInnerClass) {
class InnerClass {
private InnerClass innerClass;
private String innerName;
InnerClass(String name) {
innerName = name;
public void displayOuterInner() {
System.out.println("Non-Static:\tOuter Name: " + outerName + "\tInner Name: " + innerName);
System.out.println("");
System.out.println("final String strValueToPassToInnerClass = " + strValueToPassToInnerClass);
* @return the innerClass
public InnerClass getInnerClass() {
return innerClass;
* @param innerClass the innerClass to set
public void setInnerClass(InnerClass innerClass) {
this.innerClass = innerClass;
* @return the innerName
public String getInnerName() {
return innerName;
* @param innerName the innerName to set
public void setInnerName(String innerName) {
this.innerName = innerName;
InnerClass methodInner = new InnerClass("Inner.Donald");
methodInner.displayOuterInner();
System.out.println("My OutterClass " + outterClass.getOuterName());
// Unknown "MethodInnerClass "
public void passReferenceOfInnerClassToOtherMethod( ) {
* @param args
public static void main(String[] args) {
OutterClass outterClass = new OutterClass();
outterClass.setOuterName("Outter.Donald");
outterClass.methodWithInnerClass("This Donald is so very cool...!!! Yeah...!!!");
* @return the outerName
public String getOuterName() {
return outerName;
* @param outerName the outerName to set
public void setOuterName(String outerName) {
this.outerName = outerName;
* @return the outterClass
public OutterClass getOutterClass() {
return outterClass;
}
Similar Messages
-
Why we are making a variable as final in method inner class ?
Why we are making the variable as final (method inner class) while we are accessing the method variable in inner class ?
regards,
namancAs far as I can tell, the only reason is to protect the programmer: when the inner class instance is constructed, it is given the then-current value of the variable. If the variable (or method parameter) later changes, the value held by the inner class would not. By making the variable final, the programmer doesn't have to worry about them staying in sync.
Here's some code to ponder:
public class InnerExample
void printMe( final int x )
Runnable runMe = new Runnable()
public void run()
System.out.println(x);
(new Thread(runMe)).start();
}When compiled with the Sun JDK 1.4.2, you get this bytecode:
void printMe(int);
Code:
0: new #2; //class InnerExample$1
3: dup
4: aload_0
5: iload_1
6: invokespecial #3; //Method InnerExample$1."<init>":(LInnerExample;I)V
9: astore_2
10: new #4; //class Thread
13: dup
14: aload_2
15: invokespecial #5; //Method java/lang/Thread."<init>":(Ljava/lang/Runnable;)V
18: invokevirtual #6; //Method java/lang/Thread.start:()V
21: returnAt line (byte) 5, it loads the passed value onto the stack; at line 6, it invokes the inner class constructor (which is created by the compiler). Nothing in this sequence of code would prevent use of a non-final variable. -
Accessing the inner class written inside the method
Hi all,
Can any of you tell me how to access the inner class's method which is written inisde the outer class's method. THe code fragment is
class Outer
private static final int ID = 3;
public String name;
public void methodA( int nn )
final int serialN = 11;
class inner
void showResult()
System.out.println( "Rslt= "+ID );
} // end class inner
// new inner().showResult();
} // end methodA
class Sample
public static void main(String a[])
//access the showResult of Inner class??
Thanks in advance.
aahclass Outer {
private static final int ID = 3;
public String name;
public void methodA( int nn ) {
final int serialN = 11;
class inner {
void showResult() {
System.out.println( "Rslt= "+ID );
} // end class inner
new inner().showResult();
} // end methodA
class Sample {
public static void main(String a[]) {
new Outer().methodA(5);
} -
How to pass a JavaScript variable into a java method
I would like to know how to pass a JavaScript variable into a java method with in a <% %> tag inside a JSP file like so:
<%@ page contentType="text/html;charset=windows-1252"%>
<html>
<head>
<script LANGUAGE="JavaScript">
myValue = someDynamicValue;
<% System.out.println(myValue)%>
</script>
</head>
<body>
</body>
</html>
obviously "System.out.println(myValue)" will not work because myValue is seen as a java variable and not a JavaScript variable.
I would like to know how to let the jsp file, that I wrote in the above code, see myValue as a JavaScript variable and not a java variable so that I can pass it to a java method.
NOTE: the java method does not have to be a println() method, it can be any method of my choice.
NOTE: someDynamicValue is a JavaScript value that can dynamically changeI don't believe you can. JSPs are really just elaborate templates that an engine such as Tomcat parses and generates an HTML page based on. That page is then displayed to the user. By the time you want to use some function in Javascript, the JSP has already been parsed and generated.
Basically, Javascript and JSPs can't talk to each other. One's server-side and the other is client-side. -
How to pass a internal table used in one method to another method in a view
hi all,
Is it possible to pass a internal table from one method to another method in a view??
If so , kindly help me.Hi Bala,
If you want to pass this internal table between different methods of the same view then write the contents of this internal table to a context node of your view using BIND_TABLE. You can then read the contents of this internal table from the other method using the reference of that node & the GET_STATIC_ATTRIBUTES_TABLE method.
However if you want to pass the internal table between methods of different views then create a context node at the COMPONENTCONTROLLER level & then do a context mapping of this node to your local views context in both your views. You can follow the same BIND_TABLE & GET_STATIC_ATTRIBUTES_TABLE methods approach.
Regards,
Uday -
How to include the inner classes in a jar file in netbeans ide
Dear java friends
how to say to netbeans ide that it has to include the
inner classes in the jar file.
(i have one single applet class
with two inner classes that show up
in the build/classes file but not in the jar).
The applet works in the viewer but not
in the browser (I believe because the
xxx$yyy etc should be in the jar)
willemjavFirst, please stop posting the same question multiple times:
Duplicate of http://forum.java.sun.com/thread.jspa?threadID=5269782&messageID=10127496#10127496
with an answer.
Second, If your problem is that you can't do this in NetBeans, you need to post to somewhere that provides NetBeans support - like the NetBeans website's mailing list. These forums do not support NetBeans (or any other IDE) - they are Java language forums. -
How to pass user name and password in openConnection method ?
Hi, Exports,
I am trying to post data from applet to another application which is
protected by network password.
How to pass user name and password when I use openConnection method? In java
doc, this method looks like do not accept these two parameters.
Thanks
----- my code in applet ---------
URL url = new URL("http://127.0.0.1/xml/index.cfm");
URLConnection connection = url.openConnection();
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setUseCaches(false);
connection.setAllowUserInteraction(false);
DataOutputStream dos = new DataOutputStream(connection.getOutputStream());
dos.writeBytes("POST " + path + " HTTP/1.0\r\n");
dos.writeBytes("Referer: http://127.0.0.1/XML/index.cfm\r\n");
dos.writeBytes("Content-Type:
multipart/form-data;boundary=---------------------------7d0b414b04\r\n");
dos.writeBytes("Host: "+host+":"+port+"\r\n");
dos.writeBytes("Content-Length:" + buff.length()+"\r\n");
dos.writeBytes("Connection: Keep-Alive\r\n\n");
dos.writeBytes("-----------------------------7d0b414b04\r\nContent-Dispositi
on: form-data;name=\"xmlDoc\"\r\n\r\n");
dos.writeBytes(buff.toString());
dos.writeBytes("\r\n-----------------------------7d0b414b04--\r\n");
dos.close();
you need to negotiate Authentication in ur applet code...
For example:
If u r using Form based auth u need to send Post a request with j_user_name &
j_password to the action j_security_check. and when server returns back the
cookie
u need to hold it and pass that cookie to the each and every request made to the
protected application.
Basically u need to imitate the browser.
regards
aseem
David wrote:
> Hi, Exports,
>
> I am trying to post data from applet to another application which is
> protected by network password.
> How to pass user name and password when I use openConnection method? In java
> doc, this method looks like do not accept these two parameters.
>
> Thanks
>
> ----- my code in applet ---------
> URL url = new URL("http://127.0.0.1/xml/index.cfm");
> URLConnection connection = url.openConnection();
> connection.setDoInput(true);
> connection.setDoOutput(true);
> connection.setUseCaches(false);
> connection.setAllowUserInteraction(false);
> DataOutputStream dos = new DataOutputStream(connection.getOutputStream());
> dos.writeBytes("POST " + path + " HTTP/1.0\r\n");
> dos.writeBytes("Referer: http://127.0.0.1/XML/index.cfm\r\n");
> dos.writeBytes("Content-Type:
> multipart/form-data;boundary=---------------------------7d0b414b04\r\n");
> dos.writeBytes("Host: "+host+":"+port+"\r\n");
> dos.writeBytes("Content-Length:" + buff.length()+"\r\n");
> dos.writeBytes("Connection: Keep-Alive\r\n\n");
> dos.writeBytes("-----------------------------7d0b414b04\r\nContent-Dispositi
> on: form-data;name=\"xmlDoc\"\r\n\r\n");
> dos.writeBytes(buff.toString());
> dos.writeBytes("\r\n-----------------------------7d0b414b04--\r\n");
> dos.close();
>
> ------------------------------------------
-
How to pass tabular report col reference in the onChange event of Txtfield
Hi there
I need to have Onchange event on Textfield Item.
Whenever i change the text field value, the new value should go to particular column in my
tabular report.
So in the onchange event, i have to pass the tabular report column (target field) along with textfield value (this.value)
something like this:
onChange="javascript:changeColVal(this,rowid);"
I have no clue how to pass row id / particular column of tabular report in textfield.
Any pointers on this would be of great help.
Thanks
VijayHi Andy
Thanks a ton for your reply.
The above solution would work fine when we refer Text field within that tabular report.
but if we refer text field Item from separate HTML region?
I'm sorry, its my mistake for not providing OTN application for reference.
I've come up with dummy application which shows you exact requirement.
Please follow url: http://apex.oracle.com/pls/otn/f?p=47869:21
login credentials:
workspace: vsanthanam
user: vijay
pswd: apex_demo
Application highlights the row whenever we move up/down or click the row.
Here, i've NOTES in tabular report and Comments "text field" in separate HTML region.
Whenever i type/update comments in textfeild, it should goto Notes column in Tabular report.
so that when we move up/down the tabular report rows, it should show corresponding Notes in Comments text field.
Approach i've took:
1) Created a function hiliterow, that highlights the row clicked/move up or down and
also displays the Notes Column of Tabular report into Comments Textfield.
(this is to display Notes if already avail to that particular row, otherwise Null)
2) Function passValues would assign the value we type in Comments Text field to
Notes column of Tabular Report. (as of now, this is happening only when we click on that particular row after key-in the value in Comments txtfield,
but this should happen when onChange event on comment textfield)
3) In MoveupDown function, i'm refering the current row in var r. so i tought to have global var to hold current row, so that i can
refer the same row in Onchange Event of Textfield. But this fails (please refer NotesToRow function)
My requirement is to pass the Comments text field value to Tabular report when onChange event on Comments Text feild happens.
I'm helpless in passing row reference to onChange function.
Any pointer on this would be of immense help.
Thanks
vijay -
How to get the current class name in static method?
Hi,
I'd like to get the current class name in a static method. This class is intended to be extended. So I would expect that the subclass need not to override this method and at the runtime, the method can get the subclass name.
getClass() doesn't work, because it is not a static method.
I would suggest Java to make getClass() static. It makes sense.
But in the mean time, does anybody give an idea to work around it?
Thank you,
BillWhy not create an instance in a static method and use getClass() of the instance?
public class Test {
public static Class getClassName() {
return new Test().getClass(); -
How to pass data from one component to other component.
Hi,
I have created a table view in Item Details Page Under Price Agreement Assignment Block. Price Agreement Assignment Block has one table as standard. I have created one more view Under the Assignment block of Price agreement(CRMCMP_CND). In that view I have an option to enter data when the user click on edit. In that custom view, If user cnages to edit mode and enter data. it has to save when user click's on save button in Quotation page(BT116QH_SRVQ). From Quotation page user clicks on item to get the Item details. In the Item details there is an Price Agreement Assignment Block. In that Custom view was created and assigned to it. Data entred in that view needs to be stored when user clciks on Save button on Quotation page when he comes back. How to get the custom view data from CRMCMP_CND to BT116QH_SRVQ). Please advice. Thanks In Advance.Hi Satish,
Global custom controllers are not available everywhere. So before using them please make sure that they are available for your case.
http://sapdiary.com/index.php?option=com_content&view=article&id=2402:sap-network-blog-interaction-center-global-custom-controllers&catid=81:data-services&Itemid=81
if you find problems in navigating data using component controllers then you can also navigate it through navigation links.
If you see your outbound plug method op_xxxxx, then there is a method call to navigate method. This method has an option to pass your data collection. Pass your data collection and also inbound plug so that in target component you can read and temporarily store data as soon as you hit target component.
Hope that helps,
BJ -
How to Pass Attachment from one process to other.
Hi,
Suppose there are two processes.I am starting 2nd process from 1st process through GP API.
How to pass the attachments?
Regards,
PratikHi,
I seems its GP related. Try out the link below hope u find the solution -
How to pass control from one component to other component
Hi,
I have a requirement to pass control from one component to other component.
Here is my requirement.. l have two portal components, one is search component and other is result component. I have this search component as quick navigation iView where we can enter a value and results will display in results iView, it's a main iView.
When search view gets the results, I will display the count in search view and result in results view. .i.e.. both the iviews are viewed at any time.
Can any one advise me how to acheive this.
Thanks,
Chinna.Hi Sandeep,
Thanks for the reply. I have gone through the EPCF API, and tried with doNavigate('iViewName').
when I click on the button in search view (quikc navigation frame), instead of page getting refreshed in result iView, whole page is replaced by results iview. I want only search view and results view gets refreshed.
can you please tell me which even should I use for this scenario...
Thanks,
Chinna -
How to pass an object from jsp to other jsp using SendRedirect
How to pass an object from one jsp to the other jsp using ssendRedirect with out using the session
I am having 2 jsps
x.jsp and y.jsp
From x.jsp using sendRedirect iam going to y.jsp
From x.jsp i have pass an object to the y.jsp
Is it possible without putting the object in session
Is it possible using EncodeUrl
Please help me Its UrgentIs it possible without putting the object in sessionAnything is possible. Would you accept that it is very difficult?
When you send a redirect, it tells the browser to send a new request for the target page. That means any request parameters/attributes are lost.
Is it possible using EncodeUrl response.encodeURL() puts the session id into a url if the browser does not support cookies. It is purely for retaining the session.
There are two ways that you can communicate across a sendRedirect.
1 - use the session
2 - pass a parameter in the url.
parameters are string based, so passing objects is almost out of the question.
Potentially you could serialize your object, encode it in base64 (so it is composed completely as characters) and pass it as a parameter to the other page, where you retrieve it, unencode it, and then load the serialized object.
Or you can just use the session. -
Please help, i am so scared that i will never get my laptop back the way it was.
"the other methods aren't working"
Well, what other methods have you tried that didn't work? Frankly, your post reads as a hoax, but I have some extra time on my hands, and an idea. Make an appointment with the Apple Genius at your local Apple store. You could also bring your MBP to an AASP. Regardless, either one should be able to remove the bottom cover, and use a plastic thingy (dang, what is that tool called?) to push out the offending bit. -
How do you make a static reference to a method? I've included code.
I'm sorry but this is a cross post. This should be here but it is also in the 100% pure Java forum. It won't happen again.
Now...
Why doesn't this work? How do I use the method add(int a, int b)?
ERROR - "Can't make static reference to method int add(int, int) in testClass"
interface testInterface{
static String sString = "TESTING";
public int add(int a, int b);
class testClass implements testInterface{
public int add(int a, int b){
return a+b;
public static void main(String argv[]){
int sum = add(3,4); // here's the error
System.out.println("test");
System.out.println( sum );
}Again, I apologize for the cross post.hi,
this seems to be pretty easy, isn't it?
Oh c'mon! You try to invoke a non-static method from within a static method. Solution: Create a specific instance of class testClass:
testClass test=new testClass();
test.add(3,4);best regards, Michael
Maybe you are looking for
-
HT204364 How do I purchase more than one card at a time?
I can't figure out how to buy several cards at once without paying for shipping multiple times? Thanks
-
"Cannot send mail A copy has been placed in your outbox. The recipient was rejected by the server because it does not allow relaying." How can I fix my email? Now when I try to send an email I get the above message. It was working for months now it j
-
I have an iMac desktop from 2009 and a brand new one, I have them connected directly, migration assistant freezes every time at the one minute mark, any idea how to fix this? it seems it has something to do with one of the profiles set up on the old
-
External Speaker stopped working - get sound through headset
I have a Zire 72. The external speaker stopped working. If I listen to music or voice memos through a headset, I can hear the message so the programs are working. I have tried a soft reset but no results. Has anyone had this expierience? Sounds
-
What is theMarketing Part Number For iPod silver mini (4GB)?
Im trying to register my Ipod mini and after entering my serial number they asked for the Marketing Part Number. I had know idea where to find it.Then it said it could be found on the box. I didn't keep the box!Who does??!! Can someone please help me