Incompatible types with generics problem
Hi,
I get a mysterious compiler error:
C:\Documents and Settings\Eigenaar\Mijn documenten\NetBeansProjects\Tests\src\tests\genericstest.java:26: incompatible types
found : tests.Store<T>
required: tests.Store<T>
return store;
1 error
BUILD FAILED (total time: 0 seconds)
in the following code:
class Supply<T extends Supply<T>>{}
class Store<T extends Supply<T>>{ }
class A<T extends Supply<T>>{
private Store<T> store;
class B<T extends Supply<T>> {
public Store<T> getStore(){
return store; <-- compiler error!
}Any help would be greatly appreciated.
Edited by: farcat on Jan 13, 2009 1:23 PM
Note that the type parameter T used to define class B is not the T used to define class A. What you wrote can be more clearly written:
class Supply<T extends Supply<T>>{}
class Store<T extends Supply<T>>{ }
class A<T extends Supply<T>>{
private Store<T> store;
class B<U extends Supply<U>> {
public Store<U> getStore(){
return store;
}Which produces the more readable error message:
A.java:10: incompatible types
found : Store<T>
required: Store<U>
return store;B, being a nested, non-static class is already parameterized by T:
class Supply<T extends Supply<T>>{}
class Store<T extends Supply<T>>{ }
class A<T extends Supply<T>>{
private Store<T> store;
class B {
public Store<T> getStore(){
return store;
}
Similar Messages
-
I get the following error message:
headoffice.java:181: incompatible types
found : java.lang.String
required: int
switch (sa[3]) //sa[3] contains customer type
^
headoffice.java:183: incompatible types
found : java.lang.String
required: int
case �B�:
^
headoffice.java:186: incompatible types
found : java.lang.String
required: int
case �G�:
^
3 errors
...and it is associated with the piece of code below. I do not understand in what way the �G� and �B� are incompatible types with sa[3] which is supposed to hold strings.
StringTokenizer st=new StringTokenizer(s, �*�);
String[] sa=new String[st.countTokens()]; int i=0;
while(st.hasMoreTokens())
sa=st.nextToken();
i++;
switch (sa[3]) //sa[3] contains customer type
case �B�:
BronzeCustomer anotherBronzeCustomer = new BronzeCustomer(sa[0], sa[1]); break;
case �G�:
GoldCustomer anotherGoldCustomer = new GoldCustomer(sa[0], sa[1]); break;
default: return;
// break;
What is the problem here?
Regards
TJIf you are using only 1-character strings, then you can do:
switch (sa[3].charAt(0)) //sa[3] contains customer type
case 'B': // ...
case 'G': // ...
// etc.
} -
i am writing two classes. first one, StudentImpl.java implementing the Student interface; second one, Engine.class implementing the Auditor class. the interfaces are showed below:
Student.java:
import java.util.List;
public interface Student {
// Read-only properties
List<Double> getGrades();
String getFirstName();
String getMiddleInitial();
String getLastName();Auditor.java:
import java.util.List;
public interface Auditor {
// Read-only properties
double getClassMean();
double getClassMedian();
double getClassStandardDeviation();
List<Student> getStudents();
// Setting the data file.
void setFileName( final String fileName );
String getFileName();
// Operations
void load() throws AuditException;
}In the Engine.class. I'm having trouble with the getStudents() implemented from the Auditor interface, with the following line:
List<Student> getStudents();
the return type has to be "Student",
but my Student.java holds the Student interface, so i have StudentImpl.java to define Student
but now i seems like i have to change<Student> to <StudentImpl>, but i can't change the interface. i don't know how i am gonna solve this problem, and the compliler keeps saying: incompatible types, i have a headache today! any help will be appreciated!for MLRon. the answer is no, but at least the "incompatible type" dissappear. the problem is in the load(), which is used to load the content of a input file:
public void load() throws AuditException {
Scanner sc = null;
try {
sc = new Scanner(new File(fileName) );
while(sc.hasNextLine()){
this.students.add( new StudentImpl(sc.nextLine()) );
for(StudentImpl st : students) {
for(double g : st.getGrades()) {
add(g);
} catch (Exception e) {
throw new AuditException(e);
} finally {
if(sc != null) sc.close();
}the error is:
Driver.java:11: unreported exception AuditException; must be caught or declared to be thrown
eg.load();
^
i'm pretty sure i did throw an AuditException in the load(), now i got stuck. thanks for your help. -
Problem with incompatible types
Can you help me out where the problem is? The Child extends the Iterator<GenericTypeTest> so why the assignment doesn`t work? Thank you in advance
class GenericTypeTest implements Iterator<GenericTypeTest> {
public GenericTypeTest() {
Child a = null;
Iterator<GenericTypeTest> b = null;
b = a;
Set<Child> sa = null;
Set<Iterator<GenericTypeTest>> sb = null;
sb = sa; // HERE: COMPILATION PROBLEM
// (Incompatible types: found: Set<Child> required: Set<Iterator<GenericTypeTest>>)
public boolean hasNext() {
return false;
public GenericTypeTest next() {
return null;
public void remove() {
class Child extends GenericTypeTest {}You can only assign from a subtype to a supertype. And the subtype/supertype relationship for generic types isn't what you think it is. Read this FAQ entry for more information, especially the part around the sentence "The prerequisite is that at least one of the involved type arguments is a wildcard."
-
A question about a method with generic bounded type parameter
Hello everybody,
Sorry, if I ask a question which seems basic, but
I'm new to generic types. My problem is about a method
with a bounded type parameter. Consider the following
situation:
abstract class A{ }
class B extends A{ }
abstract class C
public abstract <T extends A> T someMethod();
public class Test extends C
public <T extends A> T someMethod()
return new B();
}What I want to do inside the method someMethod in the class Test, is to
return an instance of the class B.
Normally, I'm supposed to be able to do that, because an instance of
B is also an instance of A (because B extends A).
However I cannot compile this program, and here is the error message:
Test.java:16: incompatible types
found : B
required: T
return new B();
^
1 errorany idea?
many thanks,Hello again,
First of all, thank you very much for all the answers. After I posted the comment, I worked on the program
and I understood that in fact, as spoon_ says the only returned value can be null.
I'm agree that I asked you a very strange (and a bit stupid) question. Actually, during recent months,
I have been working with cryptography API Core in Java. I understood that there are classes and
interfaces for defining keys and key factories specification, such as KeySpec (interface) and
KeyFactorySpi (abstract class). I wanted to have some experience with these classes in order to
understand them better. So I created a class implementing the interface KeySpec, following by a
corresponding Key subclass (with some XOR algorithm that I defined myself) and everything was
compiled (JDK 1.6) and worked perfectly. Except that, when I wanted to implement a factory spi
for my classes, I saw for the first time this strange method header:
protected abstract <T extends KeySpec> T engineGetKeySpec
(Key key, Class<T> keySpec) throws InvalidKeySpecExceptionThat's why yesterday, I gave you a similar example with the classes A, B, ...
in order to not to open a complicated security discussion but just to explain the ambiguous
part for me, that is, the use of T generic parameter.
The abstract class KeyFactorySpi was defined by Sun Microsystem, in order to give to security
providers, the possibility to implement cryptography services and algorithms according to a given
RFC (or whatever technical document). The methods in this class are invoked inside the
KeyFactory class (If you have installed the JDK sources provided by Sun, You can
verify this, by looking the source code of the KeyFactory class.) So here the T parameter is a
key specification, that is, a class that implements the interface KeySpec and this class is often
defined by the provider and not Sun.
stefan.schulz wrote:
>
If you define the method to return some bound T that extends A, you cannot
return a B, because T would be declared externally at invocation time.
The definition of T as is does not make sense at all.>
He is absolutely right about that, but the problem is, as I said, here we are
talking about the implementation and not the invocation. The implementation is done
by the provider whereas the invocation is done by Sun in the class KeyFactory.
So there are completely separated.
Therefore I wonder, how a provider can finally impelment this method??
Besides, dannyyates wrote
>
Find whoever wrote the signature and shoot them. Then rewrite their code.
Actually, before you shoot them, ask them what they were trying to achieve that
is different from my first suggestion!
>
As I said, I didn't choose this method header and I'm completely agree
with your suggestion, the following method header will do the job very well
protected abstract KeySpec engineGetKeySpec (Key key, KeySpec key_spec)
throws InvalidKeySpecException and personally I don't see any interest in using a generic bounded parameter T
in this method header definition.
Once agin, thanks a lot for the answers. -
Import from database an internal table with generic Type : Web Dynpro ABAP
Hi everyone,
i have a requirement in which i'm asked to transfer data flow between two frameworks, from WD Component to another. The problem is that i have to transfer internal tables with generic types. i used the import/ export from database approache but in that way i get an error message saying "Object references and data references not yet supported".
Here is my code to extract a generic internal table from memory.
DATA l_table_f4 TYPE TABLE OF REF TO data.
FIELD-SYMBOLS: <l_table_f4> TYPE STANDARD TABLE.
DATA lo_componentcontroller TYPE REF TO ig_componentcontroller .
DATA: ls_indx TYPE indx.
lo_componentcontroller = wd_this->get_componentcontroller_ctr( ).
lo_componentcontroller->fire_vh_search_action_evt( ).
ASSIGN l_table_f4 TO <l_table_f4>.
*-- Import table for Help F4
IMPORT l_table_f4 TO <l_table_f4> FROM DATABASE indx(v1) TO ls_indx ID 'table_help_f4_ID'.
The error message is desplayed when last instruction is executed " IMPORT l_table_f4...".
I saw another post facing the same problem but never solved "Generic Type for import Database".
Please can anyone help ?
Thanks & Kind regards.hi KIan,
go:
general type
TYPE : BEGIN OF ty_itab,
field1 TYPE ztab-field1,
field2 TYPE ztab-field2,
*your own fields here:
field TYPE i,
field(30) TYPE c,
END OF ty_itab.
work area
DATA : gw_itab TYPE ty_itab.
internal table
DATA : gt_itab TYPE TABLE OF ty_itab.
hope this helps
ec -
Need help with generic class with comparable type
Hi. I'm at University, and I have some coursework to do on writing a generic class which offers ordered binary trees of items which implement the comparable interface.
I cant get the code to compile which I have written.
I get the error: OBTComparable.java uses unchecked or unsafe operations
this is the more detailed information of the error when I compile with -Xlint:unchecked
OBTComparable.java:62: warning: [unchecked] unchecked call to insert(OBTType) as
a member of the raw type OBTComparable
left.insert(insertValue);
^
OBTComparable.java:64: warning: [unchecked] unchecked call to insert(OBTType) as
a member of the raw type OBTComparable
right.insert(insertValue);
^
OBTComparable.java:75: warning: [unchecked] unchecked call to find(OBTType) as a
member of the raw type OBTComparable
return left.find(findValue);
^
OBTComparable.java:77: warning: [unchecked] unchecked call to find(OBTType) as a
member of the raw type OBTComparable
return right.find(findValue);
^
and here is my code for the class
public class OBTComparable<OBTType extends Comparable<OBTType>>
// A tree is either empty or not
private boolean empty;
// If the tree is not empty then it has
// a value, a left and a right.
// These are not used it empty == true
private OBTType value;
private OBTComparable left;
private OBTComparable right;
// Create an empty tree.
public OBTComparable()
setEmpty();
} // OBTComparable
// Make this tree into an empty tree.
private void setEmpty()
empty = true;
value = null; // arbitrary
left = null;
right = null;
} // setEmpty
// See if this is an empty (Sub)tree.
public boolean isEmpty()
{ return empty; }
// Get the value which is here.
public OBTType getValue()
{ return value; }
// Get the left sub-tree.
public OBTComparable getLeft()
{ return left; }
// Get the right sub-tree.
public OBTComparable getRight()
{ return right; }
// Store a value at this position in the tree.
private void setValue(OBTType requiredValue)
if (empty)
empty = false;
left = new OBTComparable<OBTType>(); // Makes a new empty tree.
right = new OBTComparable<OBTType>(); // Makes a new empty tree.
} // if
value = requiredValue;
} // setValue
// Insert a value, allowing multiple instances.
public void insert(OBTType insertValue)
if (empty)
setValue(insertValue);
else if (insertValue.compareTo(value) < 0)
left.insert(insertValue);
else
right.insert(insertValue);
} // insert
// Find a value
public boolean find(OBTType findValue)
if (empty)
return false;
else if (findValue.equals(value))
return true;
else if (findValue.compareTo(value) < 0)
return left.find(findValue);
else
return right.find(findValue);
} // find
} // OBTComparableI am unsure how to check the types of OBTType I am comparing, I know this is the error. It is the insert method and the find method that are causing it not to compile, as they require comparing one value to another. How to I put the check in the program to see if these two are of the same type so they can be compared?
If anyone can help me with my problem that would be great!
Sorry for the long post, I just wanted to put in all the information I know to make it easier for people to answer.
Thanks in advance
DavidI have good news and undecided news.
First the good news. Your code has compiled. Those are warnings not errors. A warning is the compiler's way of saying "I understand what you are asking but maybe you didn't fully think through the consequences and I just thought I would let you know that...[something] "
In this case it's warning you that you aren't using generics. But like I said this isn't stopping it from compiling.
The undecided news is the complier is warning you about not using generics. Are you supposed to use generics for this assignment. My gut says no and if that's true then you have no problem. If you are supposed to use generics well then you have some more work. -
Oracle 11g AQ : problem enqueue user-defined type with varchar2 attribute
Hello.
I have a problem enqueuing a user-defined type to the queue on Oracle 10g.
I'm using jdbc driver (ojdbc5.jar, version 11.1.0.6.0) as they provide oracle.jdbc.aq package.
The type is following:
CREATE OR REPLACE TYPE FIXED_T5 AS OBJECT
(id integer,
label varchar2(100),
code integer,
today date
)I have created a java class for this type with jpub utility supplied with oracle 11g client package:
jpub -user=scott/tger -url=jdbc:oracle:thin:@host:sid-sql=FIXED_T5:ru.invito.FixedType -compile=falseIt generated FixedType.java and FixedTypeRef.java files. Don't understand why i need the latter (FixedTypeRef).
Then in test app:
package ru.invito;
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.Date;
import java.util.Properties;
import java.util.UUID;
import junit.framework.TestCase;
import oracle.jdbc.aq.AQAgent;
import oracle.jdbc.aq.AQEnqueueOptions;
import oracle.jdbc.aq.AQFactory;
import oracle.jdbc.aq.AQMessage;
import oracle.jdbc.aq.AQMessageProperties;
import oracle.jdbc.aq.AQEnqueueOptions.DeliveryMode;
import oracle.jdbc.aq.AQEnqueueOptions.VisibilityOption;
import oracle.jdbc.driver.OracleConnection;
import oracle.jdbc.driver.OracleDriver;
import oracle.sql.Datum;
import oracle.sql.STRUCT;
import oracle.sql.StructDescriptor;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class AqTest extends TestCase {
protected Log logger = LogFactory.getLog(getClass());
public void testEnqueue() throws Exception {
OracleDriver dr = new OracleDriver();
Properties prop = new Properties();
prop.setProperty("user", Config.USERNAME);
prop.setProperty("password", Config.PASSWORD);
OracleConnection connection = (OracleConnection) dr.connect(Config.JDBC_URL, prop);
assertNotNull(connection);
connection.setAutoCommit(false);
enqueueMessage(connection, "INVITO.FIXED_T5Q", null);
connection.commit();
private void enqueueMessage(OracleConnection conn, String queueName, AQAgent[] recipients) throws SQLException,
IOException {
logger.debug("----------- Enqueue start ------------");
AQMessageProperties props = makeProps(queueName);
AQMessage mesg = AQFactory.createAQMessage(props);
String msqText = String.format("Hello, %s!", queueName);
FixedType data = createData(36, msqText);
Datum d = data.toDatum(conn);
STRUCT s = (STRUCT) d;
debugStruct("s", s);
String toIdStr = byteBufferToHexString(s.getDescriptor().getOracleTypeADT().getTOID(), 20);
logger.debug("s.toIdStr: " + toIdStr);
StructDescriptor sd = StructDescriptor.createDescriptor("INVITO.FIXED_T5", conn);
logger.debug("sd.toXMLString(): " + sd.toXMLString());
mesg.setPayload(s);
AQEnqueueOptions opt = makeEnqueueOptions();
logger.debug("sending............");
// execute the actual enqueue operation:
conn.enqueue(queueName, opt, mesg);
debugMessageId(mesg);
logger.debug("----------- Enqueue done ------------");
private void debugMessageId(AQMessage mesg) throws SQLException {
byte[] mesgId = mesg.getMessageId();
if (mesgId == null) {
throw new IllegalStateException("message id is NULL");
String mesgIdStr = byteBufferToHexString(mesgId, 20);
logger.debug("Message ID from enqueue call: " + mesgIdStr);
* @return
* @throws SQLException
private FixedType createData(int ID, String label) throws SQLException {
FixedType data = new FixedType();
data._struct.setNChar(1);// initializes the flag for 'label' field
data.setId(ID);
data.setLabel(label);
data.setCode(1);
Date today = new Date();
data.setToday(new Timestamp(today.getTime()));
return data;
* @param string
* @param s
* @throws SQLException
private void debugStruct(String string, STRUCT s) throws SQLException {
logger.debug(s + ".debugString(): " + s.debugString());
logger.debug(s + "s.dump(): " + s.dump());
* @return
* @throws SQLException
private AQAgent makeAgent() throws SQLException {
AQAgent ag = AQFactory.createAQAgent();
ag.setName("AQ_TEST");
String agentAddress = null;
try {
agentAddress = InetAddress.getLocalHost().getHostAddress();
catch (UnknownHostException e) {
logger.error("cannot resolve localhost ip address. will not set it as AQ Agent address");
agentAddress = "NA";
ag.setAddress(agentAddress);
return ag;
private AQMessageProperties makeProps(String queueName) throws SQLException {
final String EXCEPTION_Q_TEMPLATE = "AQ$_%sT_E";
final int DEFAULT_DELAY = 0;
final int DEFAULT_EXPIRATION = -1;
final int DEFAULT_PRIORITY = 0;
AQMessageProperties propeties = AQFactory.createAQMessageProperties();
propeties.setCorrelation(UUID.randomUUID().toString());
propeties.setDelay(DEFAULT_DELAY);
propeties.setExceptionQueue(String.format(EXCEPTION_Q_TEMPLATE, queueName));
propeties.setExpiration(DEFAULT_EXPIRATION);
propeties.setPriority(DEFAULT_PRIORITY);
// propeties.setRecipientList(null);//should not set
propeties.setSender(makeAgent());
return propeties;
* @return
* @throws SQLException
private AQEnqueueOptions makeEnqueueOptions() throws SQLException {
AQEnqueueOptions opt = new AQEnqueueOptions();
opt.setRetrieveMessageId(true);
// these are the default settings (if none specified)
opt.setDeliveryMode(DeliveryMode.PERSISTENT);
opt.setTransformation(null);
opt.setVisibility(VisibilityOption.ON_COMMIT);
return opt;
* Form the AQ reference
* @param buffer
* @param maxNbOfBytes
* @return
private static final String byteBufferToHexString(byte[] buffer, int maxNbOfBytes) {
if (buffer == null)
return null;
int offset = 0;
StringBuffer sb = new StringBuffer();
while (offset < buffer.length && offset < maxNbOfBytes) {
String hexrep = Integer.toHexString((int) buffer[offset] & 0xFF);
if (hexrep.length() == 1)
hexrep = "0" + hexrep;
sb.append(hexrep);
offset++;
String ret = sb.toString();
return ret;
}The output is following:
[main] 2008-07-03 19:09:49,863 DEBUG [ru.invito.AqTest] - ----------- Enqueue start ------------
[main] 2008-07-03 19:09:50,348 DEBUG [ru.invito.AqTest] - [email protected](): name = INVITO.FIXED_T5 length = 4 attribute[0] = 36 attribute[1] = Hell
o, INVITO.FIXED_T5Q! attribute[2] = 1 attribute[3] = 2008-07-03 19:09:49.0
[main] 2008-07-03 19:09:50,363 DEBUG [ru.invito.AqTest] - [email protected](): name = INVITO.FIXED_T5
length = 4
ID = 36
LABEL = Hello, INVITO.FIXED_T5Q!
CODE = 1
TODAY = 2008-07-03 19:09:49.0
[main] 2008-07-03 19:09:50,363 DEBUG [ru.invito.AqTest] - s.toIdStr: 507ccce5b6e9f572e040007f01007203
[main] 2008-07-03 19:09:50,363 DEBUG [ru.invito.AqTest] - sd.toXMLString(): <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<StructDescriptor sqlName="INVITO.FIXED_T5" >
<OracleTypeADT sqlName="INVITO.FIXED_T5" typecode="0" tds_version="1"
is_embedded="false" is_top_level="true" is_upt="false" finalType="true" subtype="false">
<attributes>
<attribute name="ID" type="INTEGER" >
<OracleType typecode="2" />
</attribute>
<attribute name="LABEL" type="VARCHAR2" >
<OracleType typecode="12" />
</attribute>
<attribute name="CODE" type="INTEGER" >
<OracleType typecode="2" />
</attribute>
<attribute name="TODAY" type="DATE" >
<OracleType typecode="0" />
</attribute>
</attributes>
</OracleTypeADT>
</StructDescriptor>
[main] 2008-07-03 19:09:50,379 DEBUG [ru.invito.AqTest] - sending............
[main] 2008-07-03 19:09:50,395 DEBUG [ru.invito.AqTest] - Message ID from enqueue call: 511ff143bd4fa536e040007f01003192
[main] 2008-07-03 19:09:50,395 DEBUG [ru.invito.AqTest] - ----------- Enqueue done ------------But when dequeueing the 'label' attribute is lost:
DECLARE
dequeue_options DBMS_AQ.dequeue_options_t;
message_properties DBMS_AQ.message_properties_t;
message_handle RAW(16);
message fixed_t5;
BEGIN
dequeue_options.navigation := DBMS_AQ.FIRST_MESSAGE;
DBMS_AQ.DEQUEUE(
queue_name => 'fixed_t5q',
dequeue_options => dequeue_options,
message_properties => message_properties,
payload => message,
msgid => message_handle);
DBMS_OUTPUT.PUT_LINE('ID : '||message.id);
DBMS_OUTPUT.PUT_LINE('Label: '||message.label);
DBMS_OUTPUT.PUT_LINE('Code : '||message.code);
DBMS_OUTPUT.PUT_LINE('Today: '||message.today);
COMMIT;
END;
ID : 36
Label:
Code : 1
Today: 03.07.08
Could anyone tell me what is wrong with the setup/code?
Why 'label' not saved in queue, though i saw it is not empty in STRUCT?Thank you for the reply!
I have enqueued:
[main] 2008-07-04 15:30:30,639 DEBUG [ru.invito.UserDefinedTypeAqTest$1] - [email protected](): name = INVITO.FIXED_T5
length = 4
ID = 41
LABEL = Hello, INVITO.FIXED_T5Q!
CODE = 1
TODAY = 2008-07-04 15:30:30.0and in table (select * from FIXED_T5QT) the 'label' is blank:
Q_NAME FIXED_T5Q
MSGID 51310809B5EA3728E040007F01000C79
CORRID b8f38fd3-4fa6-4e0f-85d1-2440d02d655e
PRIORITY 0
STATE 0
DELAY
EXPIRATION
TIME_MANAGER_INFO
LOCAL_ORDER_NO 0
CHAIN_NO 0
CSCN 0
DSCN 0
ENQ_TIME 04.07.2008 15:28:44
ENQ_UID INVITO
ENQ_TID 4012
DEQ_TIME
DEQ_UID
DEQ_TID
RETRY_COUNT 0
EXCEPTION_QSCHEMA AQ$_INVITO
EXCEPTION_QUEUE FIXED_T5QT_E
STEP_NO 0
RECIPIENT_KEY 0
DEQUEUE_MSGID
SENDER_NAME AQ_TEST
SENDER_ADDRESS 10.1.1.137
SENDER_PROTOCOL
USER_DATA.ID 41
USER_DATA.LABEL
USER_DATA.CODE 1
USER_DATA.TODAY 04.07.2008 15:30:30I must point to a strange thing: when the FixedType instance is created (via new operator) and then the setLabel("....") called as:
FixedType data = new FixedType();
// hack: proper initialization for 'label' field
data._struct.setNChar(1);
data.setId(ID);
data.setLabel(label);
data.setCode(1);
Date today = new Date();
data.setToday(new Timestamp(today.getTime()));
Datum d = data.toDatum(connection);
STRUCT s = (STRUCT) d;
logger.debug(s + ".debugString(): " + s.debugString());
logger.debug(s + ".dump(): " + s.dump());and if i comment line (data._struct.setNChar(1);) the debug messages for created STRUCT also shows empty value for label.
But if i explicitly call data._struct.setNChar(1) then debug contains the label i defined in call to the setLabel method. -
Nested-Generic Type with the same parameter as enclosing type?
Greetings. I want to write a nested generic type with the same type parameter as the enclosing type. For example, consider:
public interface BinaryTree<Type> {
Node<Type> getRoot();
interface Node<Type> {
Type getValue();
void setValue(Type value);
Node<Type> getLeft();
void setLeft(Node<Type> node);
Node<Type> getRight();
void setRight(Node<Type> node);
}In this example, I want Node to be specified to the same type as the binary tree's parameter specification. Does anyone know how to do that? I have tried several methods and am at a loss.
TIAIs there any way to declare that? Essentially I want
the nested type to parameterize the enclosing type.I understand that but I don't think it's possible because of how java generics works.
This ,
SomeClass< SomeNestedClass<Type> >is wrong because you're supposed to give a formal type parameter within <> not an already defined type (like SomeNestedClass).
If you instead do
public class SomeClass<Type > {
public static class SomeNestedClass<Type> {
}To think of the two Type as the same formal type parameter is semantically incorrect. Both the outer type and the inner type must be able to participate in variable declarations "on their own". Say you do
SomeClass<Integer> sc;Just because you did the above in which context is now SomeNestedClass supposed to be bound as SomeNestedClass<Integer>? To me this shows that SomeClass and SomeNestedClass cannot share the same formal type parameter. -
my phone is iphone 4 (GSM)-american type with IOS5.011 , i have problem with sim card failer (korek type)
Sounds like your iPhone is locked to AT&T. Contact them to see
if you qualify for unlocking.
This link may provide some assistance:
unlocking AT&T iPhones (thanks to wjosten for the link)
http://www.att.com/esupport/article.jsp?sid=KB414532#fbid=Ont7guWFCdY -
Problem with central build of Simple Date Type with Enumeration
Dear gurus,
I hope I'm posting this in the correct forum. Please advise if I'm in the wrong forum.
I have a Web Dynpro DC in which I've created a simple data type with enumeration. It is used for binding to a radio box. The data type is called DownloadType; the enumeration contains two vales: current and archive. To allow me to access the enumeration values, I turn on the "Generate a class representation of the enumeration" in the data type builder.
I then reference the enumeration values with code like:
if (downloadType.equals (DownloadType._CURRENT))
yada yada yada
This works fine when building locally and deploying directly. But when the DC is built by CBS (or doing a "Development Component->Build..." in NW Dev Studio), the build fails, stating that the DownloadType._CURRENT symbol cannot be resolved.
For example:
C:yadayadayada.java:227: cannot resolve symbol
symbol : variable _CURRENT
location: class yadayadayada.DownloadType
equals(DownloadType._CURRENT)) {
Apparently the central builder is not smart enough to handle the "Generate a class representation" flag.
Is this a known problem? Are there any workarounds?
Thanks in advance for any help you can provide.
-Kelly
P.S. Environment: 2004sHi Kelly,
works for me using SP10, what SP are you on?
There's a line in the DC log that says:
[ddgen] [Info] Generating datatypes/com/x/x/x/MyEnum.java
and the java compiler includes the matching path for compilation:
[echo] source paths:
[echo] ...\_comp\src\packages
[echo] ..\t\ABF37B5AFB3B2E8A76FFD29E7862EA48\gen_ddic\datatypes
Regards,
Marc -
Hashtable with incompatible types
HI, I', stuck with this. I'm trying to create a Hashtable wich will use a String as the Key and that will store my own object, but, when I try to get the information from the Hash, the compiler throws this Error:
tst.java:48: incompatible types
found : java.lang.Object
required: Entra_Usuario
U = usuario.get(usu);
The code (simplified is)
public class tst
public static void main(String[] unused)
Hashtable usuario = new Hashtable();
Entra_Usuario U = new Entra_Usuario(...Some parms);
usuario.put(usu,U);
try
while((ra = reg.readLine()) !=null)
... get data from fiel
usu= somthing from file
U = usuario.get(usu); <=== Here is where the compiler complains
if (U== null)
U = new Entra_Usuario(... );
usuario.put(usu,U);
else
U.update( ..... )
} catch (Excep...
And Class Entra_Usuario is defined as:
public class Entra_Usuario
String Fecha_Ini=null;
String Fecha_Fin=null;
String Hora_Ini=null;
String Hora_Fin=null;
String IP=null;
String Usuario=null;
public Entra_Usuario(some parms ...)
public void Update(.. some parms .)
Thx ni advance for your help
Regards Alejandroyou have to cast it :
U = (Entra_Usuario)usuario.get(usu); -
Hi,
I am trying to install JDeveloper 12c (12.1.2.0.0) (Build 6668) with Generic Installer on windows .
C:\Program Files\Java\jdk1.7.0_25\bin>java -jar C:\jdev_suite_121200.jar
I get the following error :
Extracting files................................................................
Unsupported platform (unable to determine the startup directory location).
The Oracle Universal Installer failed. Exiting.
When I try with windows install ( right click jdev_suite_121200_win32.exe and "run as administrator") , I get the following error:
ERROR Launch:No such file or directory
In the discussion (https://forums.oracle.com/thread/2573396?start=0&tstart=0) , it is said to be solved by "running as administrator" but it didn't work for me ...
Thanks ...Hi,
Can you please tell whether you are using 32-bit or 64-bit windows.
If it is 64-bit then you must run as administrator. In Windows 7x64, just right click on the jDeveloper exe and choose "run as administrator..."
Remove the existing Oracle folder and restart the system.
Try to install in new drive.
Oracle Fusion Middleware Installation Guide for Oracle JDeveloper - 11g Release 2 (11.1.2.4.0) Hope this link will give you more idea in installation.
Thanks
Pramila
Message was edited by: d6866663-7e0d-4497-89df-99f670c41872 -
Incompatible types (Generics)
Can someone explain me please the following message I've got when trying to compile a file?
incompatible types
found : java.util.Iterator<E1>
required: java.util.Iterator<E1>
If the types are identical, how can they be incompatible???!!!
Thanks.Hello,
I am stuck, I have a compilation probem. I am trying to compile my torque init class, and it gave an error message says that incompatible types. I am using Vector package to check the index of an element in the array. But the compiler found List instead of vector. Can you please tell me what's wrong.
// Begin MyProject.java source
package com.digitalevergreen.mytest;
import com.digitalevergreen.mytest.om.*;
import org.apache.torque.Torque;
import org.apache.torque.util.Criteria;
import java.util.Vector;
public class MyProject
public static void main(String[] args)
try
// Initialze Torque
Torque.init( "C:/Project/torque-3.1/Project.properties" );
// Create some Authors
Author de = new Author();
de.setFirstName( "David" );
de.setLastName( "Eddings" );
de.save();
Author tg = new Author();
tg.setFirstName( "Terry" );
tg.setLastName( "Goodkind" );
tg.save();
// Create publishers
Publisher b = new Publisher();
b.setName( "Ballantine" );
b.save();
Publisher t = new Publisher();
t.setName( "Tor" );
t.save();
// Ok. For some reason even though the BaseXPeer doInsert
// methods return the primary key it is not set in the
// BaseX save method so we have to "retrieve" these objects
// from the database or we will get null value exceptions
// when we try to use them in the book objects and do a save.
Criteria crit = new Criteria();
crit.add( AuthorPeer.LAST_NAME, "Eddings" );
Vector v = AuthorPeer.doSelect( crit );
if ( v != null && v.size() > 0 )
de = (Author) v.elementAt(0);
crit = new Criteria();
crit.add( AuthorPeer.LAST_NAME, "Goodkind" );
v = AuthorPeer.doSelect( crit );
if ( v != null && v.size() > 0 )
tg = (Author) v.elementAt(0);
crit = new Criteria();
crit.add( PublisherPeer.NAME, "Ballantine" );
v = PublisherPeer.doSelect( crit );
if ( v != null && v.size() > 0 )
b = (Publisher) v.elementAt(0);
crit = new Criteria();
crit.add( PublisherPeer.NAME, "Tor" );
v = PublisherPeer.doSelect( crit );
if ( v != null && v.size() > 0 )
t = (Publisher) v.elementAt(0);
// Create books
Book wfr = new Book();
wfr.setTitle( "Wizards First Rule" );
wfr.setCopyright( "1994" );
wfr.setISBN( "0-812-54805-1" );
wfr.setPublisher( t );
wfr.setAuthor( tg );
wfr.save();
Book dof = new Book();
dof.setTitle( "Domes of Fire" );
dof.setCopyright( "1992" );
dof.setISBN( "0-345-38327-3" );
dof.setPublisher( b );
dof.setAuthor( de );
dof.save();
// Get and print books from db
crit = new Criteria();
v = BookPeer.doSelect( crit );
for ( int i = 0; i < v.size(); i++ )
Book book = (Book) v.elementAt(i);
System.out.println("Title: " + book.getTitle() );
System.out.println("Author: " +
book.getAuthor().getFirstName()
+ " " +
book.getAuthor().getLastName() );
System.out.println("Publisher: " +
book.getPublisher().getName() );
System.out.println("\n\n");
catch (Exception e)
e.printStackTrace();
// End MyProject.java source
and this is the error message:
C:\Project\torque-3.1\src\java\com\digitalevergreen\mytest>javac MyProject.java
MyProject.java:50: incompatible types
found : java.util.List
required: java.util.Vector
Vector v = AuthorPeer.doSelect( crit );
^
MyProject.java:56: incompatible types
found : java.util.List
required: java.util.Vector
v = AuthorPeer.doSelect( crit );
^
MyProject.java:62: incompatible types
found : java.util.List
required: java.util.Vector
v = PublisherPeer.doSelect( crit );
^
MyProject.java:68: incompatible types
found : java.util.List
required: java.util.Vector
v = PublisherPeer.doSelect( crit );
^
MyProject.java:93: incompatible types
found : java.util.List
required: java.util.Vector
v = BookPeer.doSelect( crit );
^
5 errors
C:\Project\torque-3.1\src\java\com\digitalevergreen\mytest>
any help will be appreciated. Thank you in advance.
Omar N. -
Sample 1:
public interface I<T extends I<?>>
I<? extends I<T>> m1 ();
public class Z<T extends I<?>> implements I<T>
public I<? extends I<T>> m1 ()
return m2();
protected I<? extends I<T>> m2 ()
return null;
javac Z.javacompiled with no problems
Sample 2:
public interface I<Tx, T extends I<Tx, ?>>
I<Tx, ? extends I<Tx, T>> m1 ();
public class Z<Tx, T extends I<Tx, ?>> implements I<Tx, T>
public I<Tx, ? extends I<Tx, T>> m1 ()
return m2();
protected I<Tx, ? extends I<Tx, T>> m2 ()
return null;
javac Z.javaZ.java:5: incompatible types
found : I<Tx,capture of ? extends I<Tx,T>>
required: I<Tx,? extends I<Tx,T>>
return m2();
^
1 error
Well... can anyone help with this? Or at least some explanations why adding second generic generates this problem?The problem is in the recursion, not in the second type argument. If you changed your first interface from
public interface I<T extends I<?>> {} to
public interface I<T extends I<T>> {} you would run into the same error message. For sake of clarity let's discuss the issue using your first example in a slightly simplified form:
public interface I<T extends I<T>> {}
public class Z<E>
public I<? extends I<E>> m1 ()
return m2();
/* error: incompatible types
found : I<capture of ? extends I<E>>
required: I<? extends I<E>>
return m2();
^
protected I<? extends I<E>> m2 ()
{ return null; }
}The error message is not awfully helpful, because the "E" is different in both types.
Method m2 returns a reference of type I<capture of ? extends I<E>>, where E extends I<capture of ? extends I<E>>, that is, it returns a concrete instantiation of the interface, namely I<SomeType> with a type that extends I<SomeType> with a type that extends ... continued recursively.
On the other hand, method m1 is supposed to return a reference of type I<? extends I<E>>, where E extends I<? extends I<E>>, that is, it returns a wildcard instantiation of the interface, namely I<? extends I<SomeType>> with a type that extends I<? extends I<SomeType>> with a type that extends ... continued recursively.
And here is the point: The first construct leads to a concrete instantiation like a List<List<List<String>>>. The second construct lead to a recursive wildcard instantiation like List<? extends List<? extends List<?>>>. As soon as the wildcard appears on a nested level, the types are no longer compatible.
It's like assigning a List<List<String>> to a List<List<?>>. It's not permitted because the first is a list of string-lists and the second is a list of mixed-lists. You cannot assign one to the other.
In your example, changing
public interface I2<Tx, T extends I2<Tx, ?>> to
public interface I2<Tx, T extends I2<?, ?>>might do the trick.
(As usual, ignore the annoying additional angle brackets.)
Maybe you are looking for
-
Creative Zen Portable Media Center + Windows 7 = Good Stuff
Found my old Creative Zen Portable Media Center the other day while cleaning. I had put it aside since I found the process of moving/converting AVIs to it really cumbersome. Just for fun I hooked it up to my new laptop running Windows 7. It found the
-
My Tabs and Grouped Tabs were lost following reboot and not restored via History.
I closed Firefox properly and rebooted my computer. When I restarted Firefox, instead of seeing the tabs from the previous session, a window with the message that Video DownloadHelper (add on) Update 4.9.6 had been applied, and the other tabs in the
-
Hi Gurus, I am using a WBS field for which I am extracting data from R/3.But I see that in the conversion routine CONVERSION_EXIT_ABPSP_OUTPUT , CONVERSION_EXIT_KONPR_OUTPUT this function module is missing.Can I know any SAP note regarding thi
-
Linux issue: "server not responding" msgs starting to appear in DreamWeaver MX
I have an Ubuntu Server on my small network that acts (among other things) as a Web page testing server. I have DreamWeaver set up to connect to our remote host for putting operations, and the testing server is our local Linux machine. It worked grea
-
HAVING TROUBLE WITH MY TOSHIBA TV 55INCH MODEL NUMBER 55SL417U ..
HAVING TROUBLE WITH MY TOSHIBA TV 55INCH MODEL NUMBER 55SL417U ...I SET IT UP RIGHT I THINK BUT CANT GET THE HI -DEF CHANNELS ....LIKE (3-45)...THE THREE DIGIT CHANNELS...ALSO DOES THE GUIDE BOTTON EVER WORK WHY PUT IT ON THE TV IF NOT...ALL I GET WH