Statements like 'List String .class' cause error.
Consider the following simple code:
Class<List<String>> cl;
cl=List<String>.class;The first line is valid but the second one causes the "illegal start of expression" error.
That's rather strange: the type
Class<List<String>>is valid itself, but variables of that type cannot be assigned via the ".class" expression.
Is this a bug or I am missing something?
Thanks.
Java generics aren't C++ templates; they don't cause new classes to be created based on parameter type.
What this means is that for types...
List<String> stringList = new ArrayList<String>();
List<Number> numberList = new ArrayList<Number>();...the class of those lists is, in both cases, java.util.ArrayList...
string.getClass().equals(ArrayList.class);
numberList.getClass().equals(ArrayList.class);Neither class ArrayList<String> nor class ArrayList<Number> exist, because such generics information is wiped out at runtime. That's why an expression like...
ArrayList<Number>.class...is illegal.
Similar Messages
-
Changes to filter list allowed senders causes errors and emails to stop
Hi,
Running Forefront 2010 and Exchange 2007
When I change filter settings including allowed sender list and then press save my email system crashes and I see numerous errors in the event log such as:
7011 - none of the antimalware engines selected for real time scanning have been initialized
5314 - could not initialize spyware scanner
I can eventually force it back into life by restarting the Forefront Server Protection Service (that includes MS Exchange Info store and transport services) - actually a restart fails and they all need a manual restart.
Is this a "feature" or am I doing something wrong?
Thanks,
JulianHi,
are you running the latest build of FPE?
Here is the link for rollup 4:
http://support.microsoft.com/kb/2619883/en-us
And a critical hotfix for rollup 4:
http://www.microsoft.com/en-us/download/confirmation.aspx?id=41836
Greetings
Christian
Christian Groebner MVP Forefront -
Any way to assign value for variable of type Class List String ?
I'm puzzled why I can declare a variable:
Class<List<String>> clazz;but I cannot assign a value to it as
clazz = List<String>.class;The compiler also complains about
Class<List<?>> clazz0 = List<?>.class;yet it has the nerve to warn about raw types when I give up and use
Class<List> clazz0 = List.class;Even using a dummy instance does not work.
List<String> dummy = new ArrayList<String>();
Class<List<String>> clazz1 = dummy.getClass();I only care because I've declared a method like
public String useless( Class<List<String>> unSetable){
return unSetable.getName();
}And now there seems to be no way to call it.Hello chymes,
there is no way to get an instance of Class<List<String>> without at least one unchecked warning. Otherwise you could get away with the following:
List<Integer> ints = new ArrayList<Integer>();
Class<List<String>> clazz = List<String>.class;
List<String> strings = clazz.cast(ints);
strings.add("No Good");
int i = ints.get(0); // CCETherefore the only way to get it is via unchecked cast:
Class<List<String>> clazz = (Class<List<String>>) (Object) List.class;With kind regards
Ben -
Hi,
When I past the Setting properties List<String> tags = Arrays.asList("Hello", "Tutorial"); in the Eclipse I have this error:
The type List is not generic; it cannot be parameterized with arguments <String> HelloWorldServlet.java /hello-world/src/com/sap/cloud/sample/helloworld line 98 Java Problem
Why?
WeidesHi Weides...
Maybe, accidently, when you first hit "organize imports" after you pasted that code fragment, and you were asked which "List" you want to import most probably you selected java.awt.List (In java you have at least the awt list and the java.util.List)
Now... do the following:
1. Delete the import statement of import java.awt.List and delete the import java.util.List
2. Put back List<String>
3. Then, Organize Imports again , and when it prompted for the choice, choose java.util.List.
I hope that works for you.
Regards.
(PD. Useful checks will be appreciated) -
Compiler error when useing switch statements in an inner class
I have defined several constants in a class and want to use this constans also in an inner class.
All the constants are defined as private static final int.
All works fine except when useing the switch statement in the inner class. I get the compiler error ""constant expression required". If I change the definition from private static final to protected static final it works, but why?
What's the difference?
Look at an example:
public class Switchtest
private static final int AA = 0;
protected static final int BB = 1;
private static int i = 0;
public Switchtest()
i = 0; // <- OK
switch(i)
case AA: break; //<- OK, funny no problem
case BB: break; //<- OK
default: break;
private class InnerClass
public InnerClass()
i = 0; // <- OK: is accessible
if (AA == i) // <- OK: AA is seen by the inner class; i is also accessible
i = AA + 1;
switch(i)
case AA: break; // <- STRANGE?! Fail: Constant expression required
case BB: break; // <- OK
default: break;
}Thank's a lot for an explanation.Just a though:
Maybe some subclass of Switchtest could decalare its own variable AA that is not final, but it can not declare its own BB because it is visible from the superclass. Therefore the compiler can not know for sure that AA is final. -
ALV like LIST GRID BLOCKED and HIRARCHIC using oops class SALV
Hi ,
Can any one let know me is it possible to display all the Flavours of ALV like LIST GRID BLOCKED and HIRARCHICAL
using oops class CL_GUI_ALV and class CL_SALV.
and the relevant events with respect to the type of ALV.
regardsHello
Have you had a look at the documents of Rich Heilman:
[ALV Object Model - Simple 2D Table - Event Handling|https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/cda3992d-0e01-0010-90b2-c4e1f899ac01]
[ALV Object Model - Hierarchical Sequential List - The Basics|https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/b0f03986-046c-2910-a5aa-e5364e96ea2c]
[ALV Object Model - Simple 2D Table - The Basics|https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/eac1fa0b-0e01-0010-0990-8530de4908a6]
Regards
Uwe -
After upgrading to 3.6.8 none of the extensions load even though there are updates available. The updates will not install and even though the error states to look at the console error log there are no errors listed in the log. All extensions are listed in Addons>Extensions.
== This happened ==
Every time Firefox opened
== Upgrading to newer Firefox version (3.6.8)I have been having the same issue for the last two weeks. No real indication as to why it ever began other than I had turned off my router and Airport Extreme Base Station off for a weekend while I was away from my place.
iPad, iPhone, iPod Touch, all have no issues at all with my Airport Extreme Base Station. Can stay connected throughout my living room, bathroom, bedroom, no issues whatsoever.
My 5 month old MacBook Pro 2.66 GHz Core i7 Airport is sometimes perfect, able to connect, DHCP, and browse without issue. Then, for no reason, I won't be able to join my wireless network, or when I can join, I can't pick up an IP address. And then it will connect, pick up and IP, and then it won't browse. No real rhyme or reason to when this will happen, or when it works.
I thought that it was an issue with my MacBook Pro, but then my sister visited with her brand new MacBook Pro 2.26 Intel Core 2 Duo, and while a month ago she was able to connect, DHCP, and browse without issue, this weekend she had all of the same issues I was having.
My XBOX 360 and MacBook Pro have absolutely no issues with the wired connection. Only my WAN seems to have this issue.
Did you ever find anything more to this? -
Quote from Gilad Bracha's tutorial:List<String>[] lsa = new List<?>[10]; // unchecked warning - this is unsafeAt least with jdk 1.5.0_01 it does not compile at all, but gives compile error "incompatioble types. found java.,util.List<?>[]. reuired java.util.List<java.lang.String>".
This one however gives an unchecked warning:List<String>[] lsb = (List<String>[]) new List<?>[10];An error in the tutorial. Thanks for noticing. I've told Gilad.
-
Semantic Error: invalid string class
Hi, I upgraded my jdk from 1.4.2.12 to 1.5.0.12. but everytime i try to compile, the error message: "Semantic Error: A candidate for 'String' was found, but it is invalid and needs to be fixed before this type will successfully compile." any thoughts on what to do? thanks!
[sidekick Sarcastic]
kinda helps if you could show us the String that the error was pointing to. I dunno, it may kinda sorta help us figure it out, perhaps.
[sidekick Sarcastic]
With code tags :) -
What i get is only the directories and files that in other nodes. But i have also files on the root directory and i never
get them. This is a screenshot of my program after i got the content of my ftp. I'm using treeView to display my ftp content:
You can see two directories from the root but no files on the root it self. And in my ftp server host i have files in the root direcory.
This is the method i'm using to get the directory listing:
public IEnumerable<FTPListDetail> GetDirectoryListing(string rootUri)
var CurrentRemoteDirectory = rootUri;
var result = new StringBuilder();
var request = GetWebRequest(WebRequestMethods.Ftp.ListDirectoryDetails, CurrentRemoteDirectory);
using (var response = request.GetResponse())
using (var reader = new StreamReader(response.GetResponseStream()))
string line = reader.ReadLine();
while (line != null)
result.Append(line);
result.Append("\n");
line = reader.ReadLine();
if (string.IsNullOrEmpty(result.ToString()))
return new List<FTPListDetail>();
result.Remove(result.ToString().LastIndexOf("\n"), 1);
var results = result.ToString().Split('\n');
string regex =
@"^" + //# Start of line
@"(?<dir>[\-ld])" + //# File size
@"(?<permission>[\-rwx]{9})" + //# Whitespace \n
@"\s+" + //# Whitespace \n
@"(?<filecode>\d+)" +
@"\s+" + //# Whitespace \n
@"(?<owner>\w+)" +
@"\s+" + //# Whitespace \n
@"(?<group>\w+)" +
@"\s+" + //# Whitespace \n
@"(?<size>\d+)" +
@"\s+" + //# Whitespace \n
@"(?<month>\w{3})" + //# Month (3 letters) \n
@"\s+" + //# Whitespace \n
@"(?<day>\d{1,2})" + //# Day (1 or 2 digits) \n
@"\s+" + //# Whitespace \n
@"(?<timeyear>[\d:]{4,5})" + //# Time or year \n
@"\s+" + //# Whitespace \n
@"(?<filename>(.*))" + //# Filename \n
@"$"; //# End of line
var myresult = new List<FTPListDetail>();
foreach (var parsed in results)
var split = new Regex(regex)
.Match(parsed);
var dir = split.Groups["dir"].ToString();
var permission = split.Groups["permission"].ToString();
var filecode = split.Groups["filecode"].ToString();
var owner = split.Groups["owner"].ToString();
var group = split.Groups["group"].ToString();
var filename = split.Groups["filename"].ToString();
var size = split.Groups["size"].Length;
myresult.Add(new FTPListDetail()
Dir = dir,
Filecode = filecode,
Group = group,
FullPath = CurrentRemoteDirectory + "/" + filename,
Name = filename,
Owner = owner,
Permission = permission,
return myresult;
And then this method to loop over and listing :
private int total_dirs;
private int searched_until_now_dirs;
private int max_percentage;
private TreeNode directories_real_time;
private string SummaryText;
private TreeNode CreateDirectoryNode(string path, string name , int recursive_levl )
var directoryNode = new TreeNode(name);
var directoryListing = GetDirectoryListing(path);
var directories = directoryListing.Where(d => d.IsDirectory);
var files = directoryListing.Where(d => !d.IsDirectory);
total_dirs += directories.Count<FTPListDetail>();
searched_until_now_dirs++;
int percentage = 0;
foreach (var dir in directories)
directoryNode.Nodes.Add(CreateDirectoryNode(dir.FullPath, dir.Name, recursive_levl+1));
if (recursive_levl == 1)
TreeNode temp_tn = (TreeNode)directoryNode.Clone();
this.BeginInvoke(new MethodInvoker( delegate
UpdateList(temp_tn);
percentage = (searched_until_now_dirs * 100) / total_dirs;
if (percentage > max_percentage)
SummaryText = String.Format("Searched dirs {0} / Total dirs {1}", searched_until_now_dirs, total_dirs);
max_percentage = percentage;
backgroundWorker1.ReportProgress(percentage, SummaryText);
percentage = (searched_until_now_dirs * 100) / total_dirs;
if (percentage > max_percentage)
SummaryText = String.Format("Searched dirs {0} / Total dirs {1}", searched_until_now_dirs, total_dirs);
max_percentage = percentage;
backgroundWorker1.ReportProgress(percentage, SummaryText);
foreach (var file in files)
TreeNode file_tree_node = new TreeNode(file.Name);
file_tree_node.Tag = "file" ;
directoryNode.Nodes.Add(file_tree_node);
numberOfFiles.Add(file.FullPath);
return directoryNode;
Then updating the treeView:
DateTime last_update;
private void UpdateList(TreeNode tn_rt)
TimeSpan ts = DateTime.Now - last_update;
if (ts.TotalMilliseconds > 200)
last_update = DateTime.Now;
treeViewMS1.BeginUpdate();
treeViewMS1.Nodes.Clear();
treeViewMS1.Nodes.Add(tn_rt);
ExpandToLevel(treeViewMS1.Nodes, 1);
treeViewMS1.EndUpdate();
And inside a backgroundworker do work how i'm using it:
var root = Convert.ToString(e.Argument);
var dirNode = CreateDirectoryNode(root, "root", 1);
e.Result = dirNode;
And last the FTPListDetail class:
public class FTPListDetail
public bool IsDirectory
get
return !string.IsNullOrWhiteSpace(Dir) && Dir.ToLower().Equals("d");
internal string Dir { get; set; }
public string Permission { get; set; }
public string Filecode { get; set; }
public string Owner { get; set; }
public string Group { get; set; }
public string Name { get; set; }
public string FullPath { get; set; }
Now the main problem is that when i list the files and directories and display them in the treeView it dosen't get/display
the files in the root directory. Only in the sub nodes.
I will see the files inside hello and stats but i need also to see the files in the root directory.
1. How can i get and list/display the files of the root directory ?
2. For the test i tried to add to a List<string> the items in var files to see if i get the root files at all.
This is what i tried in the CreateDirectoryNode before it i added:
private List<string> testfiles = new List<string>();
Then after var files i did:
testfiles.Add(files.ToList()
But this is wrong. I just wanted to see in testfiles what items i'm getting in var files in the end of the process.
Both var files and directoryListing are IEnumerable<FTPListDetail> type.
The most important is to make the number 1 i mentioned and then to do number 2.Risa no.
What i mean is this. This is a screenshot of my ftp server at my host(ipage.com).
Now this is a screenshot of my program and you can see that in my program i have only the directories hello stats test but i don't have the files in the root: htaccess.config swp txt 1.txt 2.png....all this files i don't have it on my treeView.
What i want it to be is that on my program on the treeView i will also display the files like in my ftp server.
I see in my program only the directories and the files in the directories but i don't see the files on the root directory/node.
I need it to be like in my ftp server i need to see in my program the htaccess 1.txt 2.png and so on.
So what i wrote in my main question is that in the var files i see this files of the root directory i just don't know to add and display them in my treeView(my treeView is treeViewMS1).
I know i checked in my program in the method CreateDirectoryNode i see in the first iteration of the recursive that var files contain this root files i just dont know how to add and display them in my treeView.
On the next iterations when it does the recursive it's adding the directories hello stats test and the files in this directories but i need it to first add the root files. -
How to use string class?
Hi, experts:
Have you run HelloStrings sample in "Thinking in C++" book? The source code is following. But when I compile, it throws error:"string in not defined". How to write correct makefile? Thanks! /Denise
//: C02:HelloStrings.cpp
// The basics of the Standard C++ string class
#include <string>
#include <iostream>
using namespace std;
int main() {
string s1, s2; // Empty strings
string s3 = "Hello, World."; // Initialized
string s4("I am"); // Also initialized
s2 = "Today"; // Assigning to a string
s1 = s3 + " " + s4; // Combining strings
s1 += " 8 "; // Appending to a string
cout << s1 + s2 + "!" << endl;
} ///:~The most likely cause is that the "using namespace std;" line is missing from the file you are compiling, or commented out.
Using C++ 5.6 and the exact file I listed earlier, I get this result:
% CC -V hello.cc
CC: Sun C++ 5.6 2004/06/02
/set/mercury/dist/fcs.2/sparc-S2/opt/SUNWspro/prod/bin/c++filt: Sun C++ 5.6 2004/06/02
ccfe: Sun C++ 5.6 2004/06/02
ld: Software Generation Utilities - Solaris Link Editors: 5.9-1.377
Copy/paste the hello.cc file I listed above and try compiling it.
If you still get errors, your compiler was not installed correctly, or the installation has become corrupted.
If you want to poke around a bit more before re-installing, try this:
CC -H -c HelloStrings.cc |& grep string
The -H option lists all the header files that were read. You should see this, assuming your compiler is installed in /opt:
/opt/SUNWspro/prod/include/CC/Cstd/./string <------- string header
/opt/SUNWspro/prod/include/CC/std/string.h
/usr/include/string.h
/usr/include/iso/string_iso.h
/opt/SUNWspro/prod/include/CC/Cstd/rw/string_ref
If in particular you do not see /opt/SUNWspro/prod/include/CC/Cstd/./string, or if the "string" header marked above comes from some other location, something is definitely wrong with the compiler installation.
If you see the correct string header, run "wc" on that header. You should see this:
1858 6099 68105 string
If not, the string header is corrupted.
To re-install, refer to the Installation Guide that comes with Sun Studio 9. Follow the instructions for uninstalling Sun Studio 9. Then run the product installer, paying close attention to any warnings or error messages. I strongly recommend using the product installer, and not trying to install the product yourself directly from the packages. -
How to use List String in JSP page?
Hello All,
I am having problem using List<String> in my JSP page. Below is my JSP code.
<%@ page import="java.util.*, java.io.*"%>
<html>
<body>
<h1 align="center">Beer Recommendations JSP</h1>
<p>
<%
List<String> beerBrands = (List<String>)request.getAttribute("styles");
Iterator<String> it = beerBrands.iterator();
while(it.hasNext()){
out.print("<br>try: " + it.next());
%>
</body>
</html>
When I compile the above JSP code in Eclipse 3.4 (using JBoss 4.2 as my Application Server), I get the following Warning.
Type safety: Unchecked cast from Enumeration to Enumeration<String>
If I add the "@SuppressWarnings("unchecked")" to the code, Eclipse does not give any Error during compilation. But, at runtime, I get the following Error.
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: 10 in the jsp file: /BeerAdvice.jsp
Syntax error, annotations are only available if source level is 5.0
7: <p>
8:
9: <%
10: @SuppressWarnings("unchecked")
11: List<String> beerBrands = (List<String>)request.getAttribute("styles");
12: Iterator<String> it = beerBrands.iterator();
13: while(it.hasNext()){
An error occurred at line: 11 in the jsp file: /BeerAdvice.jsp
The type List is not generic; it cannot be parameterized with arguments <String>
8:
9: <%
10: @SuppressWarnings("unchecked")
11: List<String> beerBrands = (List<String>)request.getAttribute("styles");
12: Iterator<String> it = beerBrands.iterator();
13: while(it.hasNext()){
14: out.print("<br>try: " + it.next());
An error occurred at line: 11 in the jsp file: /BeerAdvice.jsp
Syntax error, parameterized types are only available if source level is 5.0
8:
9: <%
10: @SuppressWarnings("unchecked")
11: List<String> beerBrands = (List<String>)request.getAttribute("styles");
12: Iterator<String> it = beerBrands.iterator();
13: while(it.hasNext()){
14: out.print("<br>try: " + it.next());
Any help is very much appreciated.
Thank you for your help.
Thanks,
ChubhaHi anotherAikman,
Thank you for your help. I currently have the following version of the Java.
{color:#800000}java version "1.6.0_17"
Java(TM) SE Runtime Environment (build 1.6.0_17-b04)
Java HotSpot(TM) Client VM (build 14.3-b01, mixed mode, sharing)
{color:#000000}{color:#000000}Does it mean I have Java SE Version 6 Update 17 and you are suggesting me to download the Java EE Version 6?{color} If this is correct, can you please let me know what difference does it make?
I am now going to install the Java EE 6 and try this out.
Thank you for your help.{color}
{color:#000000}Thanks,
Chubha{color}
{color} -
Calling EJB causes error in CF Administrator
Hello,
I just moved from CFMX 6.1 Enterprise to 7 Standard and now
I'm having trouble when I invoke an EJB. The EJB returns the
information successfully, but then when I try to access the CF
Administrator, the following error is shown:
Security: The requested template has been denied access to
D:\WebSites\mntwia01\CFIDE\adminapi\administrator. cfc. The
following is the internal exception message: access denied
(java.io.FilePermission
D:\WebSites\mntwia01\CFIDE\adminapi\administrator.cfc execute)
ColdFusion cannot determine the line of the template that caused
this error. This is often caused by an error in the exception
handling subsystem.
The rest of the website works fine, but I need to restart
ColdFusion in order to be ablet to access the administrator again.
The problem happens with every EJB I call, and only since the move
to CF 7.
Thank you for any suggestions,This error seems to happen if you are debugging a function (or any subprogram with OUT parameters) and the debug call block does not assign the function's return value (and/or OUT parameters) to bind variable.
The default call block generated by SQL Developer for debugging a function ends with a statement like:
:v_Return := v_Return;
assigning the return value from the function call to a bind variable.
If you remove this bind variable entirely (say, because you used the "From File" option to load some existing script for calling the function in question), then you get the "Invalid Column Index" error. Presumably SQL Developer expects to be able to get the return value of the function out of a bind variable, so if there is nothing to bind to it gets an error.
Now, there doesn't seem to be any very good reason for this, since as far as I can tell you can't view the return value in any way after completing the debug run (and in fact, in many debug runs you may not even run the function to completion). -
Getting list of classes from a jar
Hi
I want to retrieve list of class names from a jar. i used URLClassLoader and it retrieves pakcage name but i don't know how to retrieve class namesI don't know if this is the best way, but I did this once before like this:import java.util.jar.JarEntry;
import java.util.jar.JarFile;
// then you can do this
String path = "path to some JAR file goes here";
JarFile jar = new JarFile(path);
Enumeration<JarEntry> entries = jar.entries();
while (entries.hasMoreElements())
JarEntry entry = entries.nextElement();
String name = entry.getName();
if (name.endsWith(".class"))
// this is a class entry
} -
ok, i know extending the string class is illegal because it's final, but i want to make an advanced string class that basically "extends" the string class and i've seen online this can be done through wrapper classes and/or composition, but i'm lost
here is my sample code that is coming up with numerous compile time errors due to the fact that when i declare a new AdvString object, it doesn't inherit the basic string features (note: Add is a method that can add a character to a specified location in a string)
class AdvString
private String s;
public AdvString(String s)
this.s = s;
public void Add(int pos, char ch)
int this_len = (this.length()) + 1;
int i;
for(i=0;i<(this_len);i++)
if(pos == i)
this = this + ch;
else if(pos < i)
this = this + this.charAt(i-1);
else
this = this + this.charAt(i);
public static void main(String[] args)
AdvString s1;
s1 = new AdvString("hello");
char c = 'x';
int i = 3;
s1.Add(i,c);
//s2 = Add(s1,i,c);
//String s2_reversed = Reverse(s2);
System.out.println("s1 is: " + s1);
any tips?see REString at,
http://www.geocities.com/rmlchan/mt.html
you will have to replicate all the String methods you are interested in, and just forward it to the String instance stored in REString or the like. it is like a conduit class and just passes most processing to the 'real' string. maybe a facade pattern.
Maybe you are looking for
-
My iphone 3g shows up in itunes but not my computer
I have been able to download my iphone camera roll photos for years, but my iphone no longer shows up as a device for Picasa or under "my computer". But it does show up under itunes as a device, and properly syncs my contacts to my gmail account. I
-
Problems with Photoshop Elements 9 Help Function
I recently installed Photoshop Organizer and Elements 9. When I try to access any of the first six options in the help section of the menu at the top of the window I get an Adobe AIR error message stating that the installation of this application is
-
my touchscreen is not working on my ipod 3rd generation.. any tips from any one....
-
Passing parameters to report - nothing displays
My abjective is to pass 3 parameters to a report in Forms. The user should not see the parameter form. The values passed are changed programatically based on the screen the user is on. The parameters are named the same in both Reports Builder and For
-
Is there a way to print using a canon bjc-85 with tiger?
i have just installed tiger and now my canon bjc-85 printer doesn't work with it. i have read the thread discussing this problem, and i'd be very grateful uf anyone can tell me in simple language how i can overcome this apparent incompatibility? kind