I'm working on java selenium tests and I am trying to setup a fluent/method-chaining design code: I have a generic button class that allows navigating from a page class to the other. Buttons are attributes of my pages classes. Method in the button class should be able to return generic page classes that were defined on button instantiation (the page you are on, the page the button leads to etc.). But I can't figure how to do it without breaking the fluent design in the main class: Button.java public class Button&lt;T, U&gt; {     public T observe() {         return new T(); // Does not work     }      public U click() {         return new U(); // Does not work     } }  FirstPage.java public class FirstPage {     public Button&lt;FirstPage, SecondPage&gt; buttonOnFirstPage = new Button&lt;&gt;(); }  SecondPage.java public class SecondPage {     public Button&lt;SecondPage, AnotherPage&gt; buttonOnSecondPage = new Button&lt;&gt;(); }  And finally what I want to be able to do without casting or mentioning types, in order to benefit from autocompletion and other fancy IDE stuff: BrowsingTest.java public class BrowsingTest {     public static void main(String[] args) {         new FirstPage()             .buttonOnFirstPage.observe()             .buttonOnFirstPage.click()             .buttonOnSecondPage.observe()             .buttonOnSecondPage.click(); //etc.     } }  Any idea on how I can build that button class? Thanks a lot!
Is it possible to create an instance of a generic type in Java? I'm thinking based on what I've seen that the answer is no (due to type erasure), but I'd be interested if anyone can see something I'm missing:  class SomeContainer&lt;E&gt; {     E createContents()     {         return what???     } }   EDIT: It turns out that  could be used to resolve my issue, but it requires a lot of reflection-based code, as some of the answers below have indicated.  I'll leave this open for a little while to see if anyone comes up with anything dramatically different than Ian Robertson's .
"Writ large", "Writ small", and others I have seen this used with other words besides "large" and "small".  What other words can be used? Can this structure be used more generally with other adjectives? I've not seen/read any female Orcs mentioned in the movies or in the books. In one of the movies, an Uruk-hai is momentarily shown emerging from a giant, grown-Orc sized flesh packet. So are they created with spells, or do they follow the Standard Reproductive Model. Why are news headlines in present tense if they refer to past events? In news papers we see headings like this  &quot;India signs a pact with Russia&quot; &quot;Sachin hits another century&quot; &quot;Obama wins presidential election&quot;  These are completed events, aren't they? Then, why are these sentences not mentioned in past tense? Strange error defining a macro with arguments for math mode How do I monitor the computer's CPU, memory, and disk usage in Java? I would like to monitor the following system information in Java:   Current CPU usage** (percent) Available memory* (free/total) Available disk space (free/total)  *Note that I mean overall memory available to the whole system, not just the JVM.   I'm looking for a cross-platform solution (Linux, Mac, and Windows) that doesn't rely on my own code calling external programs or using JNI. Although these are viable options, I would prefer not to maintain OS-specific code myself if someone already has a better solution.  If there's a free library out there that does this in a reliable, cross-platform manner, that would be great (even if it makes external calls or uses native code itself).  Any suggestions are much appreciated.  To clarify, I would like to get the current CPU usage for the whole system, not just the Java process(es).  The SIGAR API provides all the functionality I'm looking for in one package, so it's the best answer to my question so far. However, due it being licensed under the GPL, I cannot use it for my original purpose (a closed source, commercial product). It's possible that Hyperic may license SIGAR for commercial use, but I haven't looked into it. For my GPL projects, I will definitely consider SIGAR in the future.  For my current needs, I'm leaning towards the following:   For CPU usage, OperatingSystemMXBean.getSystemLoadAverage() / OperatingSystemMXBean.getAvailableProcessors() (load average per cpu) For memory, OperatingSystemMXBean.getTotalPhysicalMemorySize() and OperatingSystemMXBean.getFreePhysicalMemorySize() For disk space, File.getTotalSpace() and File.getUsableSpace()   Limitations:  The getSystemLoadAverage() and disk space querying methods are only available under Java 6. Also, some JMX functionality may not be available to all platforms (i.e. it's been reported that getSystemLoadAverage() returns -1 on Windows).  Although originally licensed under GPL, it  to , which can generally be used for closed source, commercial products. Any good tutorials for learning how to post-process images? I don't really know where to start with post-processing my images. I normally just straighten, crop and sharpen. Do people know of any good resources on the internet for getting a grip with Photoshop and similar tools? Let $x\in \mathbb{R}$ an irrational number. Define $X=\{nx-\lfloor nx\rfloor: n\in \mathbb{N}\}$. Prove that $X$ is dense on $[0,1)$.    Can anyone give some hint to solve this problem? I tried contradiction but could not reach a proof.  I spend part of the day studying this question   and its answers. Only one answer is clear and give clues to solve the problem. This answer is the first one. However, this answer does not answer the question nor directly, nor the proof follows from this answer.   This answer has some mistakes, he use that $[(k_1-k_2)\alpha]=[k_1\alpha]-[k_2\alpha]$ which is not true. Consider $k_1=3, k_2=1, \alpha=\sqrt{2}$ we have $[(k_1-k_2)\alpha]=2\not= 3=[k_1\alpha]-[k_2\alpha] $. We only can assure that $[k_2\alpha]-[k_1\alpha]-1\leq [(k_2-k_1)\alpha]\leq[k_2\alpha]-[k_1\alpha]$.   Who answered said something interesting about additive subgroups of $\mathbb{R}$, but unfortunately the set $X=\{nx-[nx] : n\in \mathbb{N} \}$ is not a subgroup. Considering the additive subgroup $G=\langle X \rangle$, if we prove the part (a) of the link, we get that indeed $G$ is dense on $\mathbb{R}$ but we can not conclude that $X$ is dense on $[0,1)$.  I think this problem has not been solved.  Thanks! How to know where shell variables and functions are set? When I type the set command in my system I've got this extract out :  __colormgr_commandlist='     create-device     create-profile     delete-device     delete-profile     device-add-profile     device-get-default-profile     device-get-profile-for-qualifier     device-inhibit     device-make-profile-default     device-set-kind     device-set-model     device-set-serial     device-set-vendor     find-device     find-device-by-property     find-profile     find-profile-by-filename     get-devices     get-devices-by-kind     get-profiles     get-sensor-reading     get-sensors     get-standard-space     profile-set-filename     profile-set-qualifier     sensor-lock     sensor-set-options     ' __grub_script_check_program=grub-script-check _backup_glob='@(#*#|*@(~|.@(bak|orig|rej|swp|dpkg*|rpm@(orig|new|save))))' _xspecs=([freeamp]="!*.@(mp3|ogg|pls|m3u)" [cdiff]="!*.@(dif?(f)|?(d)patch)?(.@([gx]z|bz2|lzma))" [bibtex]="!*.aux" [rgview]="*.@(o|so|so.!(conf|*/*)|a|[rs]pm|gif|jp?(e)g|mp3|mp?(e)g|avi|asf|ogg|class)" [oowriter]="!*.@(sxw|stw|sxg|sgl|doc?([mx])|dot?([mx])|rtf|txt|htm|html|?(f)odt|ott|odm)" [chromium-browser]="!*.@(?([xX]|[sS])[hH][tT][mM]?([lL]))" [tex]="!*.@(?(la)tex|texi|dtx|ins|ltx|dbj)" [netscape]="!*.@(?([xX]|[sS])[hH][tT][mM]?([lL]))" .../.. _xinetd_services ()  {      local xinetddir=/etc/xinetd.d;     if [[ -d $xinetddir ]]; then         local restore_nullglob=$(shopt -p nullglob);         shopt -s nullglob;         local -a svcs=($( printf '%s\n' $xinetddir/!($_backup_glob) ));         $restore_nullglob;         COMPREPLY+=($( compgen -W '${svcs[@]#$xinetddir/}' -- "$cur" ));     fi } dequote ()  {      eval printf %s "$1" 2&gt; /dev/null } quote ()  {      local quoted=${1//\'/\'\\\'\'};     printf "'%s'" "$quoted" } quote_readline ()  {      local quoted;     _quote_readline_by_ref "$1" ret;     printf %s "$ret" }   I checked all files in my knowledge as /etc/profile, /etc/environment, and/or ~/.bashrc. I didn't find any generation  script or code calling.   Do you have any advice where is come from ? Can spells or spell-like abilities do non-lethal damage? I'm working on a Paladin/Warlock combination, based off of , and as part of this, I noticed Miniman's remark that Repelling Blast won't be that useful, because as a Paladin, you want people up close and personal when you're in a combat situation, not further away.  However, as a Paladin, your creed sometimes leads you to not want to engage in full-blown combat with a potential adversary -- you may want to drive them off or incapacitate/capture them instead.  With this, I wonder: can Repelling Blast, or other spells and spell-likes (such as invocations), be made to do non-lethal damage?  If so, I'm thinking that it'd be useful in exactly that sort of situation -- halting someone/pushing them away without having to wade into a melee with them or blow them to smithereens. I'm searching for applications where the distribution of the eigenvalues of a unitary matrix are important. Example properties of the eigenvalues could be that the eigenvalues are clustered, that they live in some half plane, that, in the case that the matrix is orthogonal, that a certain fraction are 1, etc. I just renewed my antivirus (Kaspersky's) yesterday. After that, I logged onto Chemistry.SE (which I frequent often) but then I was greeted with this  Which was definitely not how it looked like earlier that morning. I wasn't able to  Open the reputation and badges tab Vote on questions, answers and comments (even answers to MY questions) Comment on questions or answers. 'Favorite' a question Attach tags to a question Post questions  etc., etc. But when I logged on to the Physics and Biology SEs (which I also frequent), the page format hadn't changed, but I still faced the same problems as above. Does anyone know how to fix this? P.S- I'm not a computer/formatting whiz, so you'd have to try avoiding the jargon when helping me out, sorry.... (Also I use Chrome...in case that's important.) Also @Oded recommended checking out the browser developer tools and having a look at the CSS, but as I said, I'm no Software/formatting whiz...so I'm still lost....  On @Shadow Wizard 's advice I've taken a screen shot of the 'error' notification (I had to scroll down to get all 10 'errors' on screen, hence the need for separate screen-shots) How do I apply a patch file? Converting string into datetime What procedure should be followed post spilling fluids onto a MacBook keyboard? I know the first thing to do is dry with a towel the majority of the fluid. Next is to turn off the computer. Then flip over the laptop itself and whilst upside down cool dry the keyboard with a hairdryer for a few minutes. Also leave the computer upside down for a day or so. Is there anything I’m missing? I'm starting a very long quest to learn about math, so that I can program games. I'm mostly a corporate developer, and it's somewhat boring and non exciting. When I began my career, I chose it because I wanted to create games.  I'm told that Linear Algebra is the best place to start. Where should I go? I've been looking around and I can't seem to find an automatic (i.e. buzz- or Twitter-like) way to follow users inside Stack Exchange. Why haven't the developers added such a feature? It could help beginner users follow other beginners with the same interests. We would be able to learn from each others' questions and pitfalls. Also, it would reduce double posting. I sometimes get files from my clients that have the wrong file extension. For example, the name is image.jpg but the file is actually a TIFF image. In many cases I can clarify it by opening the file in a text editor, looking at the first few bytes, then deducing which file type it is.  This works for me with JPEG, TIFF, GIF and PDF files. However there are many more file types out there.  Is it possible to automate identification of the correct file type by analyzing the containing data? app engine datastore auto-clears every time project runs Cloth collision with an object Induced metric on a null hypersurface Consider a metric $g_{\mu\nu}(x)$ and a hyper surface ${\cal H}$ defined by $~f(x) = c$. One (or at least I) usually finds the "induced metric" on ${\cal H}$ by solving$~f(x) = c$ for one of the coordinates and plugging it back into the metric to give us $\gamma_{ij}$. For null hypersurfaces, I seem to be finding that the resultant induced metric is singular.         Is it true in general that the induced metric as defined above is singular on a null hypersurface?   How does one define the induced metric on a null hypersurface?