Innerclass access of extended protected methods
I have a subclass X() which extends class Y() and has an anonymous innerclass. The innerclass extends classs z() and accesses a protected method of the extended class y(). This works fine in jdk1.3, but causes a java.lang.NoSuchMethodError in jdk1.4...
Any ideas on why it works in jdk1.3 but not in jdk1.4?
Thanks,
Bruce
Sorry, you were correct... I was going between jdk1.4
and jdk1.3 and messed up. Let me restate the problem:
I have a class CreateVLANGroup() which extends class ProvisionPanel().
Class CreateVLANGroup() creates an instance of WaitMessageHandler(). WaitMessageHandler() has a method setExecutionCommand() which takes as an argument "ExecutionCommandInterface object". CreateVLANGroup() uses an anonymous innerclass to create this argument for the call to setExecutionCommandInterface(). It is the call "CreateVLANGroup.this.displayModelData()" from within the innerclass that causes the jdk1.4 error.
See the snippet of code from CreateVLANGroup() below.
public CreateVLANGroup(PF3000View view, DMXEthernetCircuitPack model)
super(view, model);
... initialization code here
WaitMessageHandler handler = new WaitMessageHandler(this,
"Retrieving data for this Ethernet Circuit Pack, please wait...");
handler.setExecutionCommand(new ExecutionCommandInterface()
public void execute(Object target) {
if (systemProperties.isTrue("ExpandedEthernetSupported")) {
virtualIDs = m_dmxPortCircuitPack.getVRTSWFabric().getAllVRTSWIds().toArray();
if (getVirtualSwitches() != null &&
getVirtualSwitches().length != 0)
CreateVLANGroup.this.displayModelData();
else
return;
} else {
displayModelData();
handler.execute(new Object());
The actual error that I'm getting at runtime is:
java.lang.NoSuchMethodError: com.lucent.cit.gui.sysview.core.common.ProvisionPanel.access$301(Lcom/lucent/cit/gui/sysview/product/dialogs/provision/CreateVLANGroup;)V
at com.lucent.cit.gui.sysview.product.dialogs.provision.CreateVLANGroup$1.execute(CreateVLANGroup.java:58)
at com.lucent.cit.gui.util.waiting.WaitMessageHandler$WaitMessageHandlerThread.run(WaitMessageHandler.java:595)
Similar Messages
-
Java access to protected methods
Hi,
I use a java toolkit, and want to access a class (Morphy) in it.
There is only one constructor function for class Morphy:
Morphy(WordNet wn).
And here is the doc of the class Morphy.
http://nlp.stanford.edu/nlp/javadoc/wn/doc/danbikel/wordnet/Morphy.html
As some methods in this class are protected, and I will call them.
Here is my code:
import danbikel.wordnet.WordNet;
import danbikel.wordnet.Morphy;
public class wn extends Morphy {
public void test(){
wn a=new wn();
a.morphWord("running","v"); // it is a protected method in Morphy
It just report an compile error: cannot find symbol: symbol : constructor Morphy().
Can anyone tell me how to fix the problem? I don't know how to add the constructor in my code.
Thanks a lot in advance.Read [this tutorial|http://java.sun.com/docs/books/tutorial/java/IandI/super.html] from "subclass constructors" and then think about what
wn a=new wn();tries to do what it can't do. -
ALV - access to protected method
Hello,
I have a object from class "CL_GUI_ALV_GRID" and want to change the protected attribute "EVT_DELAYED_CHANGE_SELECTION Constant Protected" with the method
CALL METHOD alv_grid->SET_DELAY_CHANGE_SELECTION
EXPORTING
time = lv_delay.
How can I access this protected attribute?
Thanks in advance,
HolgerThis will do what you want
Trick is to define a sub class inheriting the super class where the protected attributes and methods exist in - then you can access the protected methods and attributes.
If you do this don't forget to call the SUPER CONSTRUCTOR (of the class you are inheriting from) in your constructor method. Code example shown below.
Here I want the original and modified table of an alv grid but you can adapt this code to whatever you need.
Hope it helps.
create blank screen (100) with a custom container CCONTAINER1 and the following scren logic in it
PROCESS BEFORE OUTPUT.
MODULE STATUS_0100.
PROCESS AFTER INPUT.
MODULE USER_COMMAND_0100.
now look at the code here. Note text in Bold
PROGRAM zdynfieldcat.
class zcltest definition deferred. "For field symbol reference.
Simple test of dynamic ITAB with user defined (not ddic) fields
Build dynamic fcat
Table structure obtained via new RTTI functionality
use ALV grid to display and edit.
Create a blank screen 100 with a custom container called CCONTAINER1.
James Hawthorne
Define field symbols as these can't be defined in classes
field-symbols: <dyn_table> type standard table,
<g2> type ref to zcltest,
<g1> type ref to cl_gui_custom_container,
<actual_tab> type standard table,
<outtab> type table,
<fs1> type ANY,
<FS2> TYPE TABLE,
<fs3> type table,
<fs4> type table,
<fs5> type table.
<b>class zcltest definition inheriting from cl_gui_alv_grid.
define this as a subclass so we can access the protected attributes
of the superclass cl_gui_alv_grid</b>
public section.
types: g4 type ref to cl_gui_custom_container.
types: g3 type ref to cl_alv_changed_data_protocol.
data: i_parent type g4,
lr_rtti_struc TYPE REF TO cl_abap_structdescr, "RTTI
zog like line of lr_rtti_struc->components. "RTTI
types: struc like zog.
types: struc1 type table of struc.
methods:
constructor
importing i_parent type g4,
disp_tab
importing p_er_data_changed type g3,
create_dynamic_fcat
importing zogt type struc1
exporting it_fldcat type lvc_t_fcat.
Protected section.
data: stab type ref to data,
wa_it_fldcat type lvc_s_fcat,
c_index type sy-index.
endclass.
<b>class zcltest implementation.
METHOD constructor.
CALL METHOD super->constructor
EXPORTING
i_appl_events = 'X'
i_parent = i_parent.
endmethod
method disp_tab.
*mt_outtab is the data table held as a protected attribute
in class cl_gui_alv_grid.
assign me->mt_outtab->* TO <outtab>. "Original data
assign p_er_data_changed->mp_mod_rows TO <FS1>.
stab = p_er_data_changed->mp_mod_rows.
assign p_er_data_changed->mt_inserted_rows to <fs3>.
assign p_er_data_changed->mt_deleted_rows to <fs4>.
assign p_er_data_changed->mt_mod_cells to <fs5>.
assign stab->* TO <fs2>.
do whatever you want with <outtab>
contains data BEFORE changes each time.
Note that NEW (Changed) table has been obtained already by
call to form check_data USING P_ER_DATA_CHANGED
TYPE REF TO CL_ALV_CHANGED_DATA_PROTOCOL.
Entered data is in table defined by <fs2>
In this method you can compare original and changed data.
Easier than messing around with individual cells.
do what you want with data in <fs2> validate / update / merge etc
endmethod.</b>
method create_dynamic_fcat.
loop at zogt into zog.
c_index = c_index + 1.
clear wa_it_fldcat.
wa_it_fldcat-fieldname = zog-name .
wa_it_fldcat-datatype = zog-type_kind.
wa_it_fldcat-inttype = zog-type_kind.
wa_it_fldcat-intlen = zog-length.
wa_it_fldcat-decimals = zog-decimals.
wa_it_fldcat-coltext = zog-name.
wa_it_fldcat-lowercase = 'X'.
if c_index eq 2.
wa_it_fldcat-emphasize = 'C411'.
endif.
if c_index eq 3.
wa_it_fldcat-emphasize = 'C511'.
endif.
append wa_it_fldcat to it_fldcat .
endloop.
endmethod. "create_dynamic_fcat
endclass. "zcltest IMPLEMENTATION
class lcl_grid_event_receiver definition.
public section.
methods:
handle_data_changed
for event data_changed of zcltest
for event data_changed of cl_gui_alv_grid
importing er_data_changed,
toolbar
for event toolbar of zcltest
importing e_object
e_interactive,
user_command
for event user_command of zcltest
importing e_ucomm.
endclass.
class lcl_grid_event_receiver implementation.
method handle_data_changed.
code whatever required after data entry.
various possibilites here as you can get back Cell(s) changed
columns or the entire updated table.
Data validation is also possible here.
call method <g2>->disp_tab
EXPORTING
p_er_data_changed = er_data_changed.
endmethod. "handle_data_changed
method toolbar.
data : ls_toolbar type stb_button.
clear ls_toolbar.
move 0 to ls_toolbar-butn_type.
move 'EDIT' to ls_toolbar-function.
move space to ls_toolbar-disabled.
move 'Edit' to ls_toolbar-text.
move icon_change_text to ls_toolbar-icon.
move 'Click2Edit' to ls_toolbar-quickinfo.
append ls_toolbar to e_object->mt_toolbar.
clear ls_toolbar.
move 0 to ls_toolbar-butn_type.
move 'UPDA' to ls_toolbar-function.
move space to ls_toolbar-disabled.
move 'Update' to ls_toolbar-text.
move icon_system_save to ls_toolbar-icon.
move 'Click2Update' to ls_toolbar-quickinfo.
append ls_toolbar to e_object->mt_toolbar.
clear ls_toolbar.
move 0 to ls_toolbar-butn_type.
move 'EXIT' to ls_toolbar-function.
move space to ls_toolbar-disabled.
move 'Exit' to ls_toolbar-text.
move icon_system_end to ls_toolbar-icon.
move 'Click2Exit' to ls_toolbar-quickinfo.
append ls_toolbar to e_object->mt_toolbar.
endmethod. "toolbar
method user_command.
case e_ucomm .
when 'EDIT'. "From Tool bar
perform set_input.
perform init_grid.
when 'UPDA'. "From Tool bar
perform refresh_disp.
perform update_table.
when 'EXIT'. "From Tool bar
leave program.
endcase.
endmethod. "user_command
endclass. "lcl_grid_event_receiver IMPLEMENTATION
program data
include <icon>.
define any old internal structure NOT in DDIC
types: begin of s_elements,
anyfield1(20) type c,
anyfield2(20) type c,
anyfield3(20) type c,
anyfield4(20) type c,
anyfield5(11) type n,
end of s_elements.
data: wa_element type s_elements,
wa_data type s_elements.
Note new RTTI functionality allows field detail retrieval
at runtime for dynamic tables.
data:
grid1 type ref to zcltest,
grid_handler type ref to lcl_grid_event_receiver,
c_dec2 type s_elements-anyfield5,
wa_it_fldcat type lvc_s_fcat,
it_fldcat type lvc_t_fcat,
lr_rtti_struc TYPE REF TO cl_abap_structdescr, "RTTI
lt_comp TYPE cl_abap_structdescr=>component_table,"RTTI
ls_comp LIKE LINE OF lt_comp, "RTTI
zog like line of lr_rtti_struc->components, "RTTI
struct_grid_lset type lvc_s_layo,
l_valid type c,
new_table type ref to data.
types: struc like zog.
data: zogt type table of struc,
grid_container1 type ref to cl_gui_custom_container,
g_event_receiver type ref to lcl_grid_event_receiver,
ok_code like sy-ucomm,
i4 type int4.
start-of-selection.
call screen 100.
module status_0100 output.
if grid_container1 is initial.
create object grid_container1
exporting
container_name = 'CCONTAINER1'.
assign grid_container1 to <g1>.
create object grid1
exporting i_parent = grid_container1.
we need reference to this instance so we can use
Methods etc of zcltest class and alv (superclass)
in our event receiver class.
assign grid1 to <g2>.
create object grid_handler.
set handler:
grid_handler->user_command for grid1,
grid_handler->toolbar for grid1,
grid_handler->handle_data_changed for grid1.
Get the Internal table structure
lr_rtti_struc ?= cl_abap_structdescr=>describe_by_data( wa_data ).
Build field catalog just use basic data here
colour specific columns as well
zogt[] = lr_rtti_struc->components.
call method grid1->create_dynamic_fcat
EXPORTING
zogt = zogt
IMPORTING
it_fldcat = it_fldcat.
Create dynamic internal table and assign to field symbol.
Use dynamic field catalog just built.
call method cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = it_fldcat
IMPORTING
ep_table = new_table.
assign new_table->* to <dyn_table>.
perform populate_dynamic_itab.
perform init_grid.
perform register_enter_event.
set off ready for input initially
i4 = 0.
call method grid1->set_ready_for_input
EXPORTING
i_ready_for_input = i4.
endif.
endmodule. "status_0100 OUTPUT
module user_command_0100 input.
*PAI not needed in OO ALV anymore as User Commands are handled as events
*in method user_command.
*we can also get control if the Data entered and the ENTER is pressed by
*raising an event.
Control then returns to method handle_data_changed.
endmodule. "user_command_0100 INPUT
form populate_dynamic_itab.
load up a line of the dynamic table
c_dec2 = c_dec2 + 11.
wa_element-anyfield1 = 'Tabbies'.
wa_element-anyfield2 = 'ger.shepards'.
wa_element-anyfield3 = 'White mice'.
wa_element-anyfield4 = 'Any old text'.
wa_element-anyfield5 = c_dec2.
append wa_element to <dyn_table>.
endform. "populate_dynamic_itab
form exit_program.
call method grid_container1->free.
call method cl_gui_cfw=>flush.
leave program.
endform. "exit_program
form refresh_disp.
call method grid1->refresh_table_display.
endform. "refresh_disp
form update_table.
The dynamic table here is the changed table read from the grid
after user has changed it
Data can be saved to DB or whatever.
loop at <dyn_table> into wa_element.
do what you want with the data here
endloop.
switch off edit mode again for next function
i4 = 0.
call method grid1->set_ready_for_input
EXPORTING
i_ready_for_input = i4.
endform. "update_table
form set_input.
i4 = 1.
call method grid1->set_ready_for_input
EXPORTING
i_ready_for_input = i4.
endform. "set_input
form switch_input.
if i4 = 1.
i4 = 0.
else.
i4 = 1.
endif.
call method grid1->set_ready_for_input
EXPORTING
i_ready_for_input = i4.
endform. "switch_input
form init_grid.
Enabling the grid to edit mode,
struct_grid_lset-edit = 'X'. "To enable editing in ALV
struct_grid_lset-grid_title = 'Jimbos Test'.
call method grid1->set_table_for_first_display
EXPORTING
is_layout = struct_grid_lset
CHANGING
it_outtab = <dyn_table>
it_fieldcatalog = it_fldcat.
endform. "init_grid
form register_enter_event.
call method grid1->register_edit_event
EXPORTING
i_event_id = cl_gui_alv_grid=>mc_evt_enter.
Instantiate the event or it won't work.
create object g_event_receiver.
set handler g_event_receiver->handle_data_changed for grid1.
endform. "register_enter_event -
Access to protected method is ot allowed
Hi,
there is class with a protected method. I get the message
"Access to protected method is ot allowed"
How must such methods be called if they are protected ?
Regards
sasErdem, please try to post in the correct forum. ABAP Objects questions belong in this forum, not general.
Second, Amit Khare is correct. The concept of Public/Protected/Private methods and attributes is not limited to ABAP Objects. It is a common concept to most object oriented programming languages. But if your read the ABAP Help on the appropriate keywords, then it is explained very clearly.
matt -
How to Access Protected Method of a Class
Hi,
I need to access a Protected method (ADOPT_LAYOUT) of class CL_REIS_VIEW_DEFAULT.
If i try to call that method by using class Instance it is giving error as no access to protected class. Is there any other way to access it..Hi,
You can create a sub-class of this class CL_REIS_VIEW_DEFAULT, add a new method which is in public section and call the method ADOPT_LAYOUT of the super-class in the new method. Now you can create an instance of the sub-class and call the new sub-class method.
REPORT ZCD_TEST.
class sub_class definition inheriting from CL_REIS_VIEW_DEFAULT.
public section.
methods: meth1 changing cs_layout type LVC_S_LAYO.
endclass.
class sub_class implementation.
method meth1.
call method ADOPT_LAYOUT changing CS_LAYOUT = cs_layout.
endmethod.
endclass.
data: cref type ref to sub_class.
data: v_layout type LVC_S_LAYO.
start-of-selection.
create object cref.
call method cref->meth1 changing cs_layout = v_layout. -
Access 2007 ADP to SQL Server 2012 with extended protection
Hello,
I have a Access 2007 ADP client connecting to an sql server 2012. This works fine with standard security configuration, but when I activate extended protection on the SQL server, the Access client cannot connect to the server. I am using integrated security
with a domain user and get the error message
"Login failed. The login is from an untrusted domain and cannot be used with Windows authentication."
In sql server logfile I find:
"SSPI handshake failed with error code 0x80090346, state 46 while establishing a connection with integrated security; the connection has been closed. Reason: The Channel Bindings from this client are missing or do not match the established Transport
Layer Security (TLS) Channel".
Is there any "easy" solution other than developing a new client based on an up to date Office version or Dot.Net?
Regards,
charles-fWell, I have no problem connecting to the sql server from my pc using ssms with my domain account. I have also sucessfully create a odbc connection using the "SQL Server Native Client 11.0" driver and my domain account. My account is in a trusted
domain, so this seems not to be the problem.
To me it rather looks like if Access is using an old driver which does not support the tls encryption required by the extended protection settings.
regards, charles-f -
Private static MyInnerClass extends OtherClass + protected methods
Hi!
Consider this case:
public class A {
private static class A1 extends B {
// this would resolve the error:
// protected static void b() { B.b(); }
void a() { A1.b(); } // ERROR: B.b() is inaccessible
public class B {
protected static void b() {}
}(Where A and B are in different packages.)
Why is B.b() inaccessible here?
A1 extends B, so it sees its protected methods.
A is a nesting class of A1, so it sees the protected methods of A1.
What am I missing here?
Thank you!
AgostonOK, my mistake, I missed the part about different
packages.
However the following further inner class of A
compiles for me:
private static class A2 extends A1
A2()
b();
A1.b();
}using the OP's original code without A1.b().That's what I was talking about: b() can be called from children, but not from the nesting class.
>
The statement quoted from the JCP exam is not
correct. The inherited protected member is available
to subclasses of A1, so the protected member
b() doesn't 'become private' at all. It stays as is
was, i.e. protected, i.e. accessible within the
original package or to subclasses.If it stays protected, why can't the nesting class see it? (Once again, a protected method defined in A1 and not inherited from B is visible from A.)
It seems as if the inherited protected method teleports into some mysterious realm of visibility levels between private and protected. (I.e. it's like protected, only from a nesting class it's seen as super-private - since the nesting class should even be able to see the private methods of its inner class, shouldn't it?)
This whole inconsequent behavior on the part of the compiler feels like a huge bug to me.
Nothing changes.Unfortunately. :)
Agoston -
ECATT: How to access a protected method of a class with eCATT?
Hi,
These is a class with a protected method. now i am willing to automate the scenario with eCATT. Since the method is Protected i am unable to use createobj and use callmethod. Could anyone suggest me a work around for this ?
Regards
Amit
Edited by: Amit Kumar on Jan 10, 2012 9:53 AMHello Anil,
You can write ABAP Code to do that inside eCATT Command.
ABAP.
ENDABAP.
Limitation of doing that is you can only use local variable inside ABAP.... ENDABAP. bracket.
Regards,
Bhavesh -
How to use protected method in jsp code
Could anyone tell me how to use protected method in jsp code ...
I declare a Calendar class , and I want to use the isTimeSet method ,
But if I write the code as follows ..
========================================================
<%
Calendar create_date = Calendar.getInstance();
if (create_date.isTimeSet) System.out.println("true");
%>
============================================================
when I run this jsp , it appears the error wirtten "isTimeSet has protected access in java.util.Calendar"The only way to access a protected variable is to subclass.
MyCalendar extends Calendar
but I doubt you need to do this. If you only want to tell if a Calendar object has a time associated with it, try using
cal.isSet( Calendar.HOUR ); -
Not sure how to use protected method in arraylisy
Hi,
Im wondering how to use the removeRange method in java arraylist, its a protected method which returns void.
http://java.sun.com/j2se/1.3/docs/api/java/util/ArrayList.html#removeRange(int,%20int)
So if my class extends Arraylist i should be able to call the method but the compiler states that it still has protected access in arraylist. Does this mean im still overriding the method in arraylist ? A little explanation of whats happeneing would be appreciated as much as an answer
thanksIn this codefinal class myClass extends java.util.ArrayList {
private ArrayList array = new ArrayList();
public myClass(ArrayList ary){
for(int i=0;i<7;i++) {
array.add(ary.get(i));
ary.removeRange(0,7)
}You are defining a class called myClass which extends ArrayList.
You have a member variable called array which is an ArrayList
You have a constructor which takes a parameter called ary which is an ArrayList
Since ary is an ArrayList, you cannot call it's removeRange() method unless myClass is in the java.util package. Do not put your class in the java.util package.
It seems like what you want to do is to move the items in one ArrayList to another ArrayList rather than copying them. I wrote a program to do this. Here it isimport java.util.*;
public class Test3 {
public static void main(String[] args) {
MyClass myClass = new MyClass();
for (int i=0; i<5; i++) myClass.add("Item-"+i);
System.out.println("------ myClass loaded -------");
for (int i=0; i<myClass.size(); i++) System.out.println(myClass.get(i));
MyClass newClass = new MyClass(myClass);
System.out.println("------ newClass created -------");
for (int i=0; i<newClass.size(); i++) System.out.println(newClass.get(i));
System.out.println("------ myClass now contains -------");
for (int i=0; i<myClass.size(); i++) System.out.println(myClass.get(i));
class MyClass extends java.util.ArrayList {
public MyClass() {}
public MyClass(MyClass ary){
for(int i=0;i<ary.size();i++) add(ary.get(i));
ary.removeRange(0,ary.size());
}You should notice now that I don't create an ArrayList anywhere. Everything is a MyClass. By the way, class names are normally capitalized, variable names are not. Hence this line
MyClass myClass = new MyClass();
In the code above I create an empty MyClass and then populate it with 5 items and then print that list. Then I create a new MyClass using the constructor which takes a MyClass parameter. This copies the items from the parameter list into the newly created MyClass (which is an ArrayList) and then removes the items from the MyClass passed as a parameter. Back in the main() method, I then print the contents of the two MyClass objects.
One thing which may be a little confusing is this line.
for(int i=0;i<ary.size();i++) add(ary.get(i));
the add() call doesn't refer to anything. What it really refers to is the newly created MyClass object which this constructor is building. This newly created object is the 'this' object. So the line above could be rewritten as
for(int i=0;i<ary.size();i++) this.add(ary.get(i));
Hopefully this helps a little. The problems you seem to be having are associated with object oriented concepts. You might try reading this
http://sepwww.stanford.edu/sep/josman/oop/oop1.htm -
Protected methods, what did i do wrong?
Hi there, I'm trying to understand why I cant access a Protected Method from a library that I'm trying to use..
Some guidance would be great:
public class Registration {
//Create new instance of ConnectionBean
ConnectionBean conBean = new ConnectionBean();
public Registration() {
public void regUser() {
String server = JOptionPane.showInputDialog( "Enter Server address" );
InetAddress inetaddress;
try {
conBean.connect( inetaddress = InetAddress.getByName( server ));
catch( UnknownHostException unknownhostexception ) {
Object aobj[] = {
"Cancel", "OK"
int i = JOptionPane.showOptionDialog(null, "Retry Server?", server +
": Not Responding", -1, 2, null, aobj, aobj[1]);
if( i == 1 )
regUser();
System.out.println( "Cannot resolve " + server + ":" + unknownhostexception.toString ());
return;
catch( IOException ioexception ) {
Object aobj1[] = {
"Cancel", "OK"
int j = JOptionPane.showOptionDialog( null, "Cannot Connect to:",
server,-1, 2, null, aobj1, aobj1[1] );
if( j == 1 )
regUser();
System.out.println( "Cannot connect " + server);
return;
System.out.println( "Registering User" );
registrationProcess();
public void registrationProcess () {
InfoQueryBuilder iqb = new InfoQueryBuilder();
InfoQuery iq;
IQRegisterBuilder iqRegb = new IQRegisterBuilder();
IQRegister iqReg = new IQRegister( iqRegb );
try {
//Need to getXMLNS packet method getXMLNS() is protected
iqReg.getXMLNS();
catch ( InstantiationException e ) {
System.out.println( "Error in building Registration packet" );
String username = JOptionPane.showInputDialog( "Enter: Username" );
String password = JOptionPane.showInputDialog( "Enter: Password" );
The error as would be expected:
Registration.java:96: getXMLNS() has protected access in org.jabber.jabberbeans.Extension.IQRegister
iqReg.getXMLNS();
^
1 error
Appreciate the help!! :)I tried to extend the class to make it a subclass of IQRegister (which holds the protected method) but I'm getting this error:
Reg.java:19: cannot resolve symbol
symbol : constructor IQRegister ()
location: class org.jabber.jabberbeans.Extension.IQRegister
public class Reg extends IQRegister {
^
1 error
Any ideas?
thanks -
How to use protected method of a particular class described in API
I read in some forum that for accessing protected method reflcetion should be used. If I'm not wrong then how can I use reflection to access such methods and if reflection isn't the only way then what is another alternative. Please help me...
regards,
JayI read in some forum that for accessing protected
method reflcetion should be used. If I'm not wrong
then how can I use reflection to access such methods
and if reflection isn't the only way then what is
another alternative. Please help me...Two ways:
- either extend that class
- or don't use it at all
If you use reflection, you're very likely to break something. And not only the design. Remember that the method is supposed to be inaccessible for outside classes. -
Protected methods in abstract classes
Hello All
I have some problem which I cannot find a workaround for.
I have three classes:
package my.one;
public abstract class First {
protected void do();
protected void now();
package my.one;
public class NotWantToHave extends First {
protected First obj;
public NotWantToHave(First O) { obj = O; }
public void do() { obj.do(); }
public void now() { obj.now(); }
package my.two;
public class Second extends my.one.First {
protected void do() { System.out.println("Second does"); }
protected void now() { System.out.println("Second does now"); }
package my.three;
public class Three extends my.one.First {
protected my.one.First obj;
public Three(my.one.First O) { obj = O; }
protected void do() { System.out.println("Doing"); }
protected void now() { obj.now(); } // Not possible, see later text
Problem is, as one can read in http://java.sun.com/docs/books/tutorial/java/javaOO/accesscontrol.html , it says that you cannot access protected members and methods from classes if they are in a different package. However, since my class Three should not concern about the method now() but should use from some other class that implements (i.e. class Second), the question I have is how to do?
One way would be to implement a class that simply make a forward call to any protected method in the same package the abstract class is in like in class NotWantToHave and pass it to the constructor of class Third while this class was created with an instance of class Second. However, such a call would look very clumsy (new my.three.Third(new my.one.NotWantToHave(new my.two.Second()));). Furthermore, everyone could create an instance of class NotWantToHave and can invoke the methods defined as protected in class First, so the access restriction would be quite useless.
Does anyone has a good idea how to do?Hi
One way I found is to have a nested, protected static final class in my super-class First and provide a protected static final method that returns a class where all methods of the super-class are made public and thus accessible from sub-classes at will. The only requirement is that a sub-class must invoke this method to encapsulate other implementations of the super-class and never publish the wrapper class instance. This will look as follows:
package my.one;
public abstract class First {
protected final static class Wrap extends First { // extend First to make sure not to forget any abstract method
protected First F;
public void do() { F.do(); }
public void now() { F.now(); }
protected Wrap(First Obj) { F = Obj; }
} // end Wrap
protected final static First.Wrap wrap(First Obj) { return new First.Wrap(Obj); }
protected abstract void do();
protected abstract void now();
} // end First*******
package my.two;
public class Second extends my.one.First {
protected void do() { System.out.println("Second does"); }
protected void now() { System.out.println("Second does now"); }
} // end Second*******
package my.three;
public class Three extends my.one.First {
protected my.one.First.Wrap obj;
public Three(my.one.First O) { obj = my.one.First.wrap(O); }
protected void do() { System.out.println("Doing"); }
protected void now() { obj.now(); } // Not possible, see later text
} // end Third*******
In this way, I can access all methods in the abstract super class since the Wrap class makes them public while the methods are not accessible from outside the package to i.e. a GUI that uses the protocol.
However, it still looks clumsy and I would appreciate very much if someone knows a more clear solution.
And, please, do not tell me that I stand on my rope and wonder why I fall down. I hope I know what I am doing and of course, I know the specification (why else I should mention about the link to the specification and refer to it?). But I am quite sure that I am not the first person facing this problem and I hope someone out there could tell me about their solution.
My requirements are to access protected methods on sub-classes of a super-class that are not known yet (because they are developed in the far, far future ...) in other sub-classes of the same super-class without make those methods public to not inveigle their usage where they should not be used.
Thanks -
Hi!
Im rhani, im new to java programming....i was trying to run this code from a book (below) :
import java.awt.*;
public class FrameExample extends Frame {
public static void main(String args[]){
FrameExample win = new FrameExample();
public FrameExample() {
super("FrameExample");
pack();
resize(400,400);
show();
public void paint(Graphics g) {
g.drawString("A Basic Window Program",100,100);
public boolean handleEvent(Event event) {
if(event.id==Event.WINDOW_DESTROY){
System.exit(0);
return true;
}else return false;
(Im using jdk1.3.1_12)
ahmm now it says that the method handleEvent is deprecated. Now then I tried to replaced it with :
protected void processEvent (AWTEvent e) {
if (e.getID == Event.WINDOW_DESTROY) {
System.exit(0);
no errors but i know my "if " condition is wrong....when i try to use e.id == WINDOW_DESTROY it says that im trying to access a protected method on that. Im just having difficulty in what really does a protected method does..or its limitations....and how would I be able to handle that the user is trying to close the frame/window. I would really do appreciate your help on this....I hope I had explained it clearly, ahm im not good in english...ahmm thank you very much!!!thank you very much sir for the fast reply...ahm i dont know if Im using the right method...ahmm its just that the documentation here http://java.sun.com/j2se/1.3/docs/api/ says that it inherits a method from Class Component, then it says that I should use processEvent, ahm the processEvent there is declared protected void processEvent ( AWTEvent e). Then on e.getID() ahm it says that it returns an int value I just thought that its value is like WINDOW_DESTROY or something...thank you very much again sir for the help...
-
I've been programming in Java for about three years, and once I believed I had understood something, but now...
I have a base class, like this:
public abstract class Base
protected abstract void method();
}I've also a derived class, like this:
public class Derived extends Base
protected void method()
System.out.println("yep!");
}And, finally, the Main class:
public class Main
public static void main(String[] args)
Base b = new Derived();
b.method();
}Now I'd expect the compiler complaining that method() of class Base is protected, hence not accessible from class Main. Instead the compiler happily builds the bytecode, the bytecode happily runs and the program happily outputs "yep!". What am I missing?I will assume that your classes are in
the default package.In fact they are.
>
protected methods are available to all classes in
the same package, and to all subclasses.So what is the difference between protected methods and "package access" ones, which are the ones without access modifier declaration such as
public abstract class Base
abstract void method();
Maybe you are looking for
-
How to use BAPI_BILLINGDOC_CREATEMULTIPLE ?
Hi, Does anyone have an example of how to use BAPI BAPI_BILLINGDOC_CREATEMULTIPLE? I am trying to create a billing document with reference to a delivery (I am hoping that this BAPI will take into account the copy control config so I won't have to do
-
I just attempted to update my iPad 2 to iOS 7. Everything went well until I got to the point where it told me that the new iOS 7 was successfully installed, the back up restored. It then directed me "slide to set up". After selecting English and my
-
Filtering response from an external servlet
Hello J2EE gurus, I have a scenario where a JSP or servlet (A) running on our server needs to call another servlet(B) running on an external server. I do not want to send the response from B back to the client but instead block it in A. From my inves
-
iphone 5 not connecting to hotspot after ios 7 dowload. pLease advise
-
What is the "Extract" button at the bottom the DNG converter dialog box for ?
Does anyone know .... What is the "Extract" button at the bottom the DNG converter dialog box for ? THANK YOU