The first is casting. The second is calling a static method on the Id
class.
One major advantage of the former is that it is more null safe.
Id idVal1 = (Id)null; // works
Id idVal2 = Id.valueOf(null); // blows up
One advantage of the latter is that you can one-line more of your code by calling instance methods on the cast result. You can get one-liners by adding some parentheses to the casting approach, though some might object on stylistic grounds. I find it a little more visually confusing.
SObjectType t1a = (Id)'001000000000000AAA'.getSObjectType(); // blows up
SObjectType t1b = ((Id)'001000000000000AAA').getSObjectType(); // works
SObjectType t2 = Id.valueOf('001000000000000AAA').getSObjectType(); // works
The above pros/cons are independent of type, so you can carry these conclusions over to String
, Decimal
, etc.