Skip to main content

Posts

Showing posts from April, 2009

Java Generics: Why I get "name clash" exception when I override methods with different "type" parameter ?

import java.util.*; class Parent { void foo(List<String> list) { System.out.println("parent"); } } class Child extends Parent { void foo(List<Integer> list) { System.out.println("child"); } } When you compile this code you will get an error like Parent.java:7: name clash: foo(java.util.List<java.lang.Integer>) in Child and foo(java.util.List<java.lang.String>) in Parent have the same erasure, yet neither overrides the other class Child extends Parent { ^ 1 error This "name clash" error thrown because of "type erasure" thing when "generics" code gets complied. Let’s see how, When we complied any generics code, the compiler removes the type from the code and treat it as a simple pre Java 1.5 code, like, in our case, compiler saw something like this, import java.util.*; class Parent { void foo(List list) { // oops, <String> get erased. System.out.println("parent"); } } class Child extend

Remove PK, FK constraint from SQL Server table

I'm weak in databases and consult Google every time if I'm new to the concept OR baffled somewhere. Some days back I got simple requirement which is nothing but to drop the PK constraint from a table, Initially I thought it was easy to do but got stuck and finally came up with solution.This is what straight forward thing I did -- Problem: Remove the PK constraint from the table 'test', -- Solution: -- 1. Get the table constraint using following query SELECT CONSTRAINT_NAME FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE TABLE_NAME = 'test'; -- 2. It returns a column CONSTRAINT_NAME with the list of constraint, like, PK, FK, etc --|CONSTRAINT_NAME| ------------------- --|PK_test | -- 3. The PK constraint name generally starts with "PK_table_name[_xxx]" -- 4. Remove it using following query ALTER TABLE test DROP CONSTRAINT PK_test; -- 5. You just drop the PK constraint from table 'test', hurray !!! :) Hope this hel