Typesafe enums with private access - strange or useful?

Given the class listed at the bottom, you'll notice that it's possible to specify a typesafe enum, and restrict that enum to clients in such a way that - and here's the strange part - the constant class is not exported in the api, despite the fact that it's required as an argument to the constructor.
In other words you can legally state:
MyClass myClass = new MyClass(MyClass.PLAIN);but not:
MyClass.Constant constant = MyClass.PLAIN;
MyClass myClass = new MyClass(constant);Anyone else noticed this? (Still coming to terms with the meaning of it).
/k1
Example code:
* Type safety demo
package blah;
* Demo class showing the use of inaccessible constants
public class MyClass {
     /** My first constant */
     public static final Constant FIRST;
     /** My second constant */
     public static final Constant SECOND;
     /* The instance constant field */
     private Constant constant;
     /* static initialiser for the constants */
     static {
          FIRST = new Constant("First");
          FANCY = new Constant("Second");
      * @param constant The constant spec
     public MyClass(Constant constant) {
          super();
          this.constant = constant;
     private static class Constant {
          private String name;
           * @param name The name of my constant
          public Constant(String name) {
               this.name = name;
}

And indeed outside the package...
package blah.test;
import blah.*;
public class Driver {
      * Main method for the sake of demonstration...
     public static void main(String[] args) {
          Object[] constants = MyClass.VALUES;
          for (int i = 0; i < constants.length; i++) {
               System.out.println(constants);
               MyClass myClass = new MyClass(constants[i]);
               System.out.println(myClass);
...then...
* Type safety demo
package blah;
* Demo class showing the use of inaccessible constants
public class MyClass {
     /** My first constant */
     public static final Constant FIRST = new Constant("First");
     /** My second constant */
     public static final Constant SECOND = new Constant("Second");
     /** An array of the constants */
     public static final Constant[] VALUES = { FIRST, SECOND };
     /* The instance constant field */
     private Constant constant;
      * @param constant The constant spec
     public MyClass(Object constant) {
          super();
          if (constant instanceof Constant) {
               this.constant = (Constant)constant;
     private static class Constant {
          private String name;
           * @param name The name of my constant
          public Constant(String name) {
               this.name = name;
           * @return The name of the constant
          public String toString() {
               return name;

Similar Messages

  • How does private access scope manifest itself?

    Hi,
    I am in the process of converting an old project to use Project Libraries (*.lvlib). I have read and watched all the tutorials, LV Help sections, etc. I understand the benefits of using project libraries. But, I still do not understand how access to VIs is restricted after setting their scope to private. For example, I can create a new VI, outside the project library, then "Select a VI" to place on the block diagram, using a subVI with private access from a project library. And I can can run this test VI without any apparent problem.
    So, I seem to be able to access a 'private' VI. How and where is the access restricted for a VI with private scope?
    Thanks,
    RonC
    Solved!
    Go to Solution.

    Hi Chris,
    No example required...I can explain.     
    You know, after trying and trying to sort this out myself, and not being able to, I knew that when I asked, it would turn out to be something stupid. Here is what happened...
    I was using the "Data Acquisition Reference Design" project example as a reference to sort this out. I think this is an excellent one. I looked at the Configuration module and Display module sub-libraries, and the scope is just as described in the tutorials; i.e. the API VIs marked Public and the subVIs marked Private.
    Then, for my little example VI, I used a "Private" subVI from the Logging module, because it did not require any other resources to run, it just checked the root directory.  It worked fine, and hence my confusion. But, after you told me that should not work, I looked again, and out of the four sub-libraries used in the example, two (the two I looked at) have the access set as described, but the other two do not -- everything is Public. And, of course I used one of the public ones.
    I just tried again, using a "Private" subVI from the Display module, and although I can see it and place it on my block diagram, my calling VI is broken, the reason given is because of the private scope.
    Doh! I have only been doing this for 22 years, so not yet long enough to avoid the dumb mistakes I guess.
    Thanks for setting me straight.
    RonC
    P.S. I am using LV 2010 SP1

  • Integrating Oracle EBS R12 with Oracle Access Manager 11g

    Hi Everyone ,
    Oracle Access Manager version 11.1.1.5
    Oracle Identity Management 11.1.1.6.0
    Oracle Access Manager WebGate 11.1.1.5
    Oracle E-Business Suite AccessGate patch p12796012
    Apps Version : 12.1.1
    DB Version 11.2.0.3
    PLatform : OEL 5.8
    We are trying to Integrating Oracle E-Business Suite Release 12 with Oracle Access Manager 11g using Oracle E-Business Suite AccessGate.We followed metalink id's
    1309013.1 and 1543803.1 and some other documents.We have performed every step as documented , and everything seems to work fine untill user tries to log out from Oracle Applications i.e User
    is able to login to Oracle Applications through access gate and everything is working fine. But as user click logout button an error messsage is diplayed like "*500*
    *Internal Server Error Servlet error: An exception occured* " (The url at the time of this message is http://hostname:port/OA_HTML/AppsLogout ).
    Apps Tier (oacore) Application log:-
    +13/05/15 19:04:20.229 html: Servlet error+
    java.lang.NoSuchMethodError: oracle.apps.fnd.sso.SSOManager.getAuthAgentLogoutUrl(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
    at oracle.apps.fnd.sso.AppsLogoutRedirect.doGet(AppsLogoutRedirect.java:193)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:743)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
    +at com.evermind[Oracle Containers for J2EE 10g (10.1.3.4.0) ].server.http.ResourceFilterChain.doFilter(ResourceFilterChain.java:64)+
    at oracle.apps.jtf.base.session.ReleaseResFilter.doFilter(ReleaseResFilter.java:26)
    +at com.evermind[Oracle Containers for J2EE 10g (10.1.3.4.0) ].server.http.EvermindFilterChain.doFilter(EvermindFilterChain.java:15)+
    at oracle.apps.fnd.security.AppsServletFilter.doFilter(AppsServletFilter.java:318)
    +at com.evermind[Oracle Containers for J2EE 10g (10.1.3.4.0) ].server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:621)+
    +at com.evermind[Oracle Containers for J2EE 10g (10.1.3.4.0) ].server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:370)+
    +at com.evermind[Oracle Containers for J2EE 10g (10.1.3.4.0) ].server.http.HttpRequestHandler.doProcessRequest(HttpRequestHandler.java:871)+
    +at com.evermind[Oracle Containers for J2EE 10g (10.1.3.4.0) ].server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:453)+
    Apps Tier Apache Error log :-
    +[Wed May 15 18:50:52 2013] [error] [client 192.168.0.2] [ecid: 1368624052:192.168.0.61:10798:0:44,0] File does not exist: /u01/eBiZR12/apps/apps_st/comn/java/classes//+
    WE have set all required profile in Oracle Application as directed in documents , and users are able to login just fine , but they are not able to logout.
    IS there something that we are missing , any help is highly appreciated.
    Regards
    Edited by: TheKop88 on May 16, 2013 11:39 AM

    Hi there ,
    Thanks for reply ,
    We had already gone through that document earlier. We noticed that when Apllication Profile "*Apllications SSO Type* " is set to SSWA then OA_HTML/AppsLogout is
    working fine , but when we set "*Applications SSO Type*" to SSWA w/SSO then OA_HTML/AppsLogout is not working(not redirecting) .Error thrown on web browser is "+500 Internal Server Error Servlet error: An exception occurred. The current application deployment descriptors do not allow for including it in this response+" . we believe that we might have missed some Profile settings that is causing this error.
    Regards
    Edited by: TheKop88 on May 16, 2013 12:03 PM
    Edited by: TheKop88 on May 16, 2013 12:07 PM

  • An error occured when connecting java with Ms Access

    Hello Everybody
    I am a new developer in java and want to connect java with Microsoft Access
    i am using JCreator LE
    My code is to insert 3 records for 3 members and then save them in DB and retrieve the information
    Here is the code
    import java.sql.*;
    public class Project3 {
        public static void main(String[] args) {
             try {
                  System.out.println("Beginning Connection");
                Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                String accessFileName = "Information";
                String connURL = "jdbc:odbc:;DRIVER=Microsoft Access Driver (*.mdb);DBQ="+accessFileName+".mdb;PWD=";
                Connection con = DriverManager.getConnection( connURL ,"","");
                Statement stmt = con.createStatement();
                System.out.println("Connection done successfully");
                stmt.execute("Create table Member(Name String,ID Integer)");
                stmt.execute("insert into Member values ('Joe','1234')");
                stmt.execute(" select * from Member");
                ResultSet rs=stmt.getResultSet();
                if (rs != null)
                     while (rs.next()){
                          System.out.println("Name: "+rs.getString("Name")+ "ID: " + rs.getString("ID"));
                stmt.close();
                con.close();
                catch (Exception e) {
                System.out.println("An error Occurred in Connecting with the DB " );
    }and the error is
    Beginning Connection
    Connection done successfully
    An error Occurred in Connecting with the DB
    it didn't insert information in the DB

    Well, thank u i have traced the error and fx it
    but
    how to modify the code and keep the user entering 3 values and search for the entered values??
    Here is the correct code
    import java.sql.*;
    public class Project3 {
        public static void main(String[] args) {
             try {
                  System.out.println("Beginning Connection");
                Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                String accessFileName = "jdbc:odbc:Project";
                String connURL = "jdbc:odbc:;DRIVER=Microsoft Access Driver (*.mdb);DBQ="+accessFileName+".mdb;PWD=";
                Connection con = DriverManager.getConnection( accessFileName);
                Statement stmt = con.createStatement();
                System.out.println("Connection done successfully");
                stmt.execute("Create table Member(Name String,ID Integer)");
                stmt.execute("insert into Member values ('Joe','1234')");
                stmt.execute(" select * from Member");
                ResultSet rs=stmt.getResultSet();
                if (rs != null)
                     while (rs.next()){
                          System.out.println("Name: "+rs.getString("Name")+ "ID: " + rs.getString("ID"));
                stmt.close();
                con.close();
                catch (Exception err) {err.printStackTrace();}
    }

  • Enums with common method implementation.

    Working with JDK 1.4 , i had some typesafe enums with common methods in an abstract class. Because of some issues, i want to migrate them to 'enums' provided in JDK 5.
    As enum provided in JDK 5 can neither be extended or derived from any other class, i am unable to achieve my objective.
    Is there any way out, or should i continue to live with my old code?
    Thanks,
    Prabhaker

    Well, there's always this ugly pretend-you-have-multiple-inheritance sort of construct:
    public class CommonEnumUtilities
        // the following method is the actual implementation of method foo
        public static void foo(Enum e, Object... otherParams)
    public interface CommonEnumInterface
        // the following ensures that you have the method foo
        public void foo(Object... otherParams);
    public enum SomeEnum implements CommonEnumInterface
        public void foo(Object... otherParams)
            CommonEnumUtilities.foo(this, otherParams);
    }I personally find this approach revolting, but I guess it's better than nothing.

  • Safari Crash - Problem with doodle (planer) app  -  doodle web links cause safari to crash with a very strange message "Error - Please make sure Safari is not used in Private Modus" (translated from german) No Privat Modus buttom in ios 7 safari settings!

    Safari Crash - Problem with doodle (planer) app  -  doodle web links cause safari to crash with a very strange message "Error - Please make sure Safari is not used in Private Modus" (translated from german) No Privat Modus buttom in ios 7 safari settings! Works fine with an older Safari Version. Web link, call doodle app.  You could see the website in the backround working but safari crashes after clicking on the error window.   Any suggestions?

    Turn off Private Browsing.
    Tap "Private" on Safari Screen to disable Private Browsing. When top of screen is white, Private Browsing is off.

  • Login codes using java database (validates with Microsoft Access File)

    hi all pro-programmer, can you show me the code to login with the username and password using java database. When the user enters the username and password in the login page then it will go to the requested page. may i know how to do it?

    no one will give you complete code.
    i'll lay out the pieces for you, though:
    (1) start with a User object. give it username and password attributes.
    (2) write a UserDAO interface with CRUD operations for a User object.
    (3) write a UserDAOImpl for your Microsoft Access database
    (4) write an AuthenticationService interface
    (5) write an implementation of the AuthenicationService that works with the UserDAO to authorize a User.
    Use a servlet to accept request from your login page and pass it off to the service. Voila.
    PS - Here's skeleton to start with. UI, servlet, and controller are your responsibility:
    package model;
    public class User implements Serializable
        private String username;
        private String password;
        public User(String u, String p)
            this.username = u;
            this.password = p;
        public String getUsername() { return username; }
        public String getPassword() { return password; }
    public interface UserDAO
        public User findByUsername(String username);
        public void saveOrUpdate(User user);
        public void delete(User user);
    public class UserDAOImpl implements UserDAO
        private Connection connection;
        public UserDAOImpl(Connection connection)
            this.connection = connection;
        public User findByUsername(String username)
            String password = "";
            // logic for querying the database for a User
            return new User(username, password);
        public void saveOrUpdate(User user)
            // save or update a User
        public void delete(User user)
            // delete a User
    public interface AuthenticationService
        public boolean isAuthorized(String username);
    public class AuthenticationServiceImpl implements AuthenticationService
        private UserDAO userDAO;
        public AuthenticationServiceImpl()
            // Create a database connection here and the UserDAO, too.
        public boolean isAuthorized(String username)
            boolean isAuthorized = false;
            // Add logic to do the database query and decide if the username is authorized
            return isAuthorized;       
    }

  • I can't read Or write I have been using the iPad With the accessibility icon Is there a video help them teach me how to use it more efficiently

    I cannot read or write I have been using the iPad With the accessibility icon  Is there a video to help teach me To learn how to use this accessibility more efficiently

    It sounds like you may have multiple problems, but none of them are likely to be caused by malware.
    First, the internet-related issues may be related to adware or a network compromise. I tend to lean more towards the latter, based on your description of the problem. See:
    http://www.adwaremedic.com/kb/baddns.php
    http://www.adwaremedic.com/kb/hackedrouter.php
    If investigation shows that this is not a network-specific issue, then it's probably adware. See my Adware Removal Guide for help finding and removing it. Note that you mention AdBlock as if it should have prevented this, but it's important to understand that ad blockers do not protect you against adware in any way. Neither would any kind of anti-virus software, which often doesn't detect adware.
    As for the other issues, it sounds like you've got some serious corruption. I would be inclined to say it sounds like a failing drive, except it sounds like you just got it replaced. How did you get all your files back after the new drive was installed?
    (Fair disclosure: I may receive compensation from links to my sites, TheSafeMac.com and AdwareMedic.com, in the form of buttons allowing for donations. Donations are not required to use my site or software.)

  • I have an iPhone with an unlimited data plan. Is there a way to go online with a wifi only iPad using my phone for access?

    I have an iPhone with an unlimited data plan. Is there a way to go online with a wifi only iPad using my phone for access?

    If your iPhone cell carrier allows you to use Tethering, you can turn your iPhone into a wifi hotspot, then your iPad Air can connect to that for internet access.  Not all cell carriers allow tethering without you signing up for additional fees/services.  For example, AT&amp;T in the US still has grandfathered "unlimited" data plans, but they do not allow tethering for those plans.  With AT&amp;T you need to switch to a Mobile Share plan (or a tiered plan if still available) to use tethering (legally).

  • How to get the extension Info from firefox? Do we have any firefox API to communicate with the browser? I couldnt see the HTML of the widget displayed in the toolbar how to access the widget using JS or any way

    How to get the extension Info from firefox? Do we have any firefox API to communicate with the browser? I couldnt see the HTML of the widget displayed in the toolbar how to access the widget using JS or any way

    Hi,
    Thanks for the suggestion. I've been playing around with some of the classes of the java.net package and java.io
    Using the URL class i can get the content of the data from a STATIC page and output that response to file so that is does not display to the client broswer.
    But this only works if the URL i give points to a static html page.
    So the problem i'm getting is if i'm righting in arguments in the URL, this means that server needs to process the arguments i give and its sends back a dynamic result. Because its dynamic the URL class can not handle this and throws me an exception everytime :(
    Have u ever tried to do some things like this?
    Rahul

  • Using DataSource with MS Access

    is it possible to use the JDBC DataSource with MS Access? Should I download some .class to register with JNDI?

    I've done it with Tomcat, but I've never tried to do it outside of a container. You sound like you want to do it without a servlet or J2EE app server engine acting as the lookup and pool. - MOD

  • Using RowSet with MS Access

    sun.jdbc.rowset.JdbcRowSet doesn't work with MS Access ?
    It raises java.sql.SQLException: Invalid Cursor Type: 1003, 0, null
    sun.jdbc.rowset.CachedRowSet doesn't work either:
    How can I use JdbcRowSet or CachedRowSet with MS Access ?
    try {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    // initialize our RowSet
    JdbcRowSet titleRs = new JdbcRowSet();
    titleRs.setUrl("jdbc:odbc:Test-Adressen"); // example DSN
    titleRs.setCommand("SELECT id, title from Titles");
    titleRs.execute();
    //next line throws Exception :
    titleRs.moveToInsertRow();//move to construct an insert row
    titleRs.updateString(2, "Dipl.-Ing.");// initialize phone
    titleRs.insertRow(); // insert the row
    titleRs.moveToCurrentRow(); // move back to
    // previous cursor position
    titleRs.next();
    catch (SQLException se) {
    System.out.println( se+", "+se.getErrorCode()+", "+se.getSQLState());
    se.printStackTrace();
    catch (Throwable t) {
    System.out.println( t);
    t.printStackTrace();
    Output:
    java.sql.SQLException: Invalid Cursor Type: 1003, 0, null
    JdbcRowSet (setTypeMap): null
    JdbcRowSet (setMaxFieldSize): [Microsoft][ODBC Microsoft Access Driver]Optionales Feature wurde nicht implementiert.
    JdbcRowSet (setQueryTimeout): [Microsoft][ODBC Microsoft Access Driver]Optionales Feature wurde nicht implementiert.
    java.sql.SQLException: Invalid Cursor Type: 1003
    at sun.jdbc.odbc.JdbcOdbcResultSet.moveToInsertRow(JdbcOdbcResultSet.java:4143)
    at sun.jdbc.rowset.JdbcRowSet.moveToInsertRow(JdbcRowSet.java:2658)
    at de.CoSoCo.relations.Title.main(Title.java:72)
    note on error message : using german version of MS Access
    please answer also to [email protected]

    Hi Ulf,
    also der Fehler kommt mir irgendwie bekannt vor. :) Ich muss mal schauen, wie ich den umschifft habe. Aber es liegt wohl eben auch an Access das Cursor Manipulation nicht geht. Wenn ich den Sourcecode gefunden habe mail ich ihn Dir.
    Cu
    Olaf

  • Can I use Web Services with Microsoft Access?

    I'm somewhat handy with Microsoft Access (2003 in particular), but not an expert. Macros? No problem. VBA? I'd be hard pressed to code anything from scratch, but I'm not too bad with modifying code/examples to fit my particular scenario. So, if anything about this doesn't ring quite right, now you'll know why. Some years ago I worked with another guy to develop a module that used REST(?) to query some web services at Yahoo!. If that worked, I was hoping that I could do similar things with CRMOD I was thinking, for example, I might want to get the Opportunity Sales Stage for a number of records. And since there are tools for Excel and Word, I thought Access might work, too. As a starting point, I imagine I need to use the Web Services Toolkit for Office 2003. But frankly, I don't even know where to go beyond that.
    Am I wasting my time? Any suggestions for an intro to web services?

    Probably not through USB.
    But likely if its anytihng like the Microsoft Sync in my Ford Explorer you can play audio from it through Bluetooth.
    You can read here for compatibilites, and features.
    http://www.ford.com/technology/sync/
    I connect My iPad to the Sync media center with no issues and can play my musci from the iPad thorugh the car stereo speakers.

  • Using BEA Weblogic Portal with Sun Access Manager

    Hello all,
    I am wondering if anyone has had experience with using Weblogic Portal (versions 8.1 or 9.2) with Sun's Access Manager tool (part of the Identity Management suite).
    In particular, I would like to know what access control tasks were performed through access manager, and which were performed portal-side.
    Any information would be appreciated.
    Thanks!

    Hi
    Has any one explored the below question.
    Is WLP 9.2 compatible with Sun Access Manager?
    If yes, please let know the details.
    Thanks

  • I'm on Vacation with no access to my Mac.  But had tried Sync. My software update is iOS 6.0.1. I've tried another WiFi network.  I read your comment of deleting Apps for stuck update. So removed all Apps! Can't even install Free Apps. Now using my Kindle

    I'm on Vacation with no access to my Mac.  But had tried Sync. My software update is iOS 6.0.1. I've tried another WiFi network.  I read your comment of deleting Apps for stuck update. So removed all Apps! Can't even install Free Apps. Now using my Kindle

    Purplehiddledog wrote:
    I do backup with iCloud.  I can't wait until the new iMac is available so that I can once again have my files in more than 1 location without needing to rely solely on the cloud. 
    I also rely on iTunes and my MacBook and Time Machine as well as backing up to iCloud. I know many users know have gone totally PC free, but I chose to use iCloud merely as my third backup.
    I assume that the restore would result in my ability to open Pages and Numbers and fix the problem with deleting apps, but this would also mean that if my Numbers documents still exist solely within the app and are just not on iCloud for some reason that they would be gone forever.  Is that right?
    In a word, yes. In a little more detail.... When you restore from an iCloud backup, you must erase the device and start all over again. There is no other way to access the backup in iCloud without erasing the device. Consequently, you are starting all over again. Therefore, it would also be my assumption that Pages and Numbers will work again and that the deleting apps issues would be fixed as well.
    If the documents are not in the backup, and you do not have a backup elsewhere, the documents could be gone forever.

Maybe you are looking for

  • Setting up site to site vpn with cisco asa 5505

    I have a cisco asa 5505 that needs to be set up for site to site vpn to a cisco asa 5500. The 5505 is the remote office and the 5500 is the main office. IP of remote office router is 71.37.178.142 IP of the main office firewall is 209.117.141.82 Can

  • Transaction iView issue: Table Can't Support multi-cell copy pase

    Hey guys:               I have a big problem. The transaction iview's content is a ABAP application, and it cannot support mulit-cell copy-pase when user try to pase their data from Excel. It only allow single cell copy-pase each time, and that means

  • Best way to recover from incorrect migration

    Let me start out by saying that we know we did things incorrectly, and that "doing it over again the right way" isn't the advice we're looking for in this discussion. Here's the situation: Existing database instance (A) is Oracle 10g on AIX. New data

  • Hits count In KM

    Hi Friends We are working on implementing KMC for a customer. We have one requirement in which we need to find the hit cont of every document in KM. Do we have any out of the box solution for this? Also i have found out a portal component provided by

  • Partition tables replication

    Can anyone let me know how to replicate partitioned tables using goldengate.