This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Demonstrate how to call setFixedLengthStreamingMode with an int argument in | |
* Java 6 and with a long argument in Java 7. | |
*/ | |
import java.lang.reflect.Method; | |
import java.net.HttpURLConnection; | |
import java.net.URL; | |
public class SetFixedLengthStreamingMode { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.TreeMap; | |
public class CaseInsensitiveMap { | |
public static void main(String[] args) { | |
TreeMap<String, String> map = new TreeMap<String, String>( | |
String.CASE_INSENSITIVE_ORDER); | |
assert map.isEmpty(); | |
map.put("a", "b"); | |
assert map.size() == 1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Demonstrate that exception catch order is relevant and javac warns when | |
* catching a more specific exception after a less specific one: | |
* | |
* CatchOrder.java:20: exception java.io.FileNotFoundException has already been caught | |
* } catch (FileNotFoundException fnfe) { | |
* ^ | |
* 1 error | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ cat foo.java | |
public class foo { | |
private foo() {} | |
public static String method(int x, Long y) { | |
return "x: " + x + " y: " + y.longValue(); | |
} | |
} | |
$ javac foo.java |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum { uninitialized, initializing, initialized }; | |
static state = uninitialized; | |
static var = 0; | |
while (true) { | |
switch(cmpxchg(state, initializing, uninitialized)) { | |
case uninitialized: | |
var = stmt; | |
xchg(state, initialized); | |
return; | |
case initializing: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ cat -n atomic.cc | |
1 #include <atomic> | |
2 | |
3 int func(std::atomic<int> *x) | |
4 { | |
5 return std::atomic_load(x); | |
6 } | |
$ g++ -O2 -std=c++0x -S -o - atomic.cc | |
.file "atomic.cc" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ cat foo.c | |
#include <stdio.h> | |
#include <stdlib.h> | |
char *func1(void) { return malloc(256); } | |
char *func2(void) { return func1(); } | |
int main(int argc, char *argv[]) | |
{ | |
char *ptr = func2(); |
NewerOlder